我有一个这样的字符串,它是从数据库中获取的:
user=me@example.com&name=John
Run Code Online (Sandbox Code Playgroud)
我想知道是否有一种简单的方法来提取数据并将其放入两个变量,用户和名称。
@Marc,根据@Dan Bracuk的建议,您可以先使用提及的分隔符,&然后再使用来拆分字符串=。请参考下面的代码,对您有帮助。我希望。
<cfset yourInput= 'user=me@example.com&name=John'>
<!--- Get the first value. I mean "user" part --->
<cfset splitFirstPart = listfirst(yourInput,'&', true)>
<cfset splitLastPart = listlast(yourInput, '&', true)>
<!--- Get the second part value --->
<!--- Above values are split by using & --->
<cfset user = listlast(splitFirstPart, '=', true)>
<Cfset name = listlast(splitLastPart, '=', true)>
<!---
Now we can again split the list by using =.
Now you can see the result.
--->
<cfoutput>
User : #user# <br/>
Name : #name#
</cfoutput>
Run Code Online (Sandbox Code Playgroud)
如果您需要任何其他CFML功能和说明,请参阅https://cfdocs.org/
谢谢。
| 归档时间: |
|
| 查看次数: |
180 次 |
| 最近记录: |