Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 566
  • Last Modified:

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

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.
0
LeadCo
Asked:
LeadCo
  • 2
  • 2
1 Solution
 
azadisaryevCommented:
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.
0
 
LeadCoAuthor Commented:
Can you provide the code to parse the data so i may see how it works?
0
 
azadisaryevCommented:
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>
0
 
LeadCoAuthor Commented:
Great! Are you Looking  for work? leadco@bellsouth.net
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now