How do you parse "pipe delimited data" with coldfusion. Example..

LeadCo
LeadCo used Ask the Experts™
on
How do you parse this:

Code is setu like this:
Var1|Value1|Var2|Value2|Var3|Value3

Code that needs parsed:
Status|Rejected|PingId|4102|Payout|0

I need to pull out each variable ( status, Pingid, Payout)

God bless.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
that's easy - just treat your variable as a |-delimited list and use appropriate cf list functions or cfloop over the |-delimited list to get the keys/values you need.

one thing to keep in mind: cf treats consecutive list delimiters as one delimiter!
so make sure there are no empty list elements: before you parse the list, change any || to | | (that is pipe-space-pipe) using replace() cf function.

Author

Commented:
Can you provide the code to parse the data so i may see how it works?
Example:

<cfset mylist = "Status|Rejected|PingId|4102|Payout|0">
<cfset mylist = replace(mylist, "||", "| |", "all")>
<cfoutput>
<cfloop from="1" to="#listlen(mylist, '|')#" index="x" step="2">
#listgetat(mylist, x, "|")#=#listgetat(mylist, x+1, "|")#<br />
</cfloop>
</cfoutput>

OR, if you just want to extrace a value of a specific key from the list, say PingId key:
<cfoutput>
PingID = #listgetat(mylist, listfindnocase(mylist, "PingId", "|")+1, "|")#
</cfoutput>

Author

Commented:
Great! Are you Looking  for work? leadco@bellsouth.net

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial