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

Posted on 2008-11-16
Last Modified: 2013-12-16
How do you parse this:

Code is setu like this:

Code that needs parsed:

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

God bless.
Question by:LeadCo
    LVL 27

    Expert Comment

    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 Comment

    Can you provide the code to parse the data so i may see how it works?
    LVL 27

    Accepted Solution


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

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

    Author Closing Comment

    Great! Are you Looking  for work?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
    When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
    This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
    The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now