gpt4 book ai didi

ColdFusion - 字符串到变量

转载 作者:行者123 更新时间:2023-12-04 16:57:32 25 4
gpt4 key购买 nike

我有一个这样的字符串,我从数据库中得到:

user=me@example.com&name=John

我想知道是否有一种简单的方法来提取数据并将它们放入两个变量中,用户和名称。

最佳答案

@Marc,根据@Dan Bracuk 的建议,您可以首先使用提到的分隔符将字符串拆分为 &再次作为 = .请引用我下面的代码,这将对您有所帮助。我希望。

Runnable Example

<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>

如果您需要任何其他 CFML 功能和说明,请参阅 https://cfdocs.org/

谢谢。

关于ColdFusion - 字符串到变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55810004/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com