Reputation: 27
I have a string like:
oauth_token=xxxxxxxxxxx&oauth_token_secret=xxxxxxxxxxx&oauth_callback_confirmed=true
I want to extract these values into three variables.
Can you please suggest the easiest method in ColdFusion?
Upvotes: 0
Views: 2595
Reputation: 2525
There is another alternative to the accepted solution:
<cfset t = "oauth_token=abc&oauth_token_secret=def&oauth_callback_confirmed=true">
<cfset oauth_token = ListGetAt(ListGetAt(t,1,"&"),2,"=")>
<cfset oauth_token_secret = ListGetAt(ListGetAt(t,2,"&"),2,"=")>
<cfset oauth_callback_confirmed = ListGetAt(ListGetAt(t,3,"&"),2,"=")>
Upvotes: 0
Reputation: 3036
@Dan Bracuk was close, this will do what you want.
<cfset myString = "oauth_token=xxxxxxxxxxx&oauth_token_secret=xxxxxxxxxxx&oauth_callback_confirmed=true">
<cfloop list="#myString#" index="pair" delimiters="&">
<cfset myStruct[ListFirst(pair, "=")] = ListLast(pair, "=")>
</cfloop>
<cfdump var="#myStruct#">
Upvotes: 6
Reputation: 20804
I would try something like this:
<cfloop
list = "oauth_token=xxxxxxx&oauth_token_secret=xxxxx&oauth_callback_confirmed=true"
index="pair" delimiter="&">
<cfset ListFirst(pair, "=") = ListLast(pair, "=")>
</cfloop>
I'm not sure if it work, but it would be worth a shot.
Upvotes: 1