Ignore some delimiters

Discussion in 'Programming' started by tbarr60, May 30, 2007.

  1. #1
    I'd like to loop through a list that is comma delimited but I'd like to skip the commas that would appear with in a delimited string. Here's an example:

    "Fred, Ethel", "Fred, Wilma"

    I'd like the comma inside the quotes to be viewed as part of a string not as a delimiter. Is there any clean way to do this?
     
    tbarr60, May 30, 2007 IP
  2. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    One way is to change the delimiter from a comma to something else, like a pipe symbol "|"

    <cfset yourString = '"Fred, Ethel", "Fred, Wilma"'>
    <cfset newString = reReplace(yourString, '"[ ]*,[ ]*"', '"|"', "all")>
    <cfloop list="#newString#" index="elem" delimiters="|">
    <cfoutput>#elem# <br/></cfoutput>
    </cfloop>
     
    cfStarlight, May 30, 2007 IP