Skip to main content
Known Participant
August 17, 2009
Question

commas in a list surrounded by quotes

  • August 17, 2009
  • 2 replies
  • 1271 views

I am trying to use listgetat but when it is passed a string that has commas in it... it screws up.

test = "this is my string,'this, is,another'";

testoutput = listgetat(test,2);

gives me 'this

Is there a way to get it to recognize the whole second string?

    This topic has been closed for replies.

    2 replies

    Prasanth_Kumar_S
    Inspiring
    August 17, 2009

    If you like to separate string having comma, the best method is use a different delimiter, or use combination delimiter such as ":;" (without quotes).

    -Prasanth

    whoisit28Author
    Known Participant
    August 17, 2009

    I was unable to change the delimiters as this has already been implimented.

    This was my fix:

    <cfset stringlen = len(mystring)>
        <cfset inside = 0>
        <cfset newstring = "">
        <cfloop from="0" to="#stringlen-1#" index="x">
            <cfset thischar = arguments.docTitleList.charat(x)>
            <cfif thischar eq '"' and inside eq 0>
                <cfset inside = 1>
                <cfset thischar = "">
            <cfelseif thischar eq '"' and inside eq 1>
                <cfset inside = 0>
                <cfset thischar = "">
            </cfif>
            <cfif thischar eq "," and inside eq 1>
                <cfset thischar = "|">
            </cfif>
            <cfset newstring = newstring&thischar>
        </cfloop>

    Inspiring
    August 17, 2009

    Try this:

    delim = "','",

    testoutput = listgetat(test,2,delim);

    whoisit28Author
    Known Participant
    August 17, 2009

    thanks for the reply, but I don't think that would work if their weren't any single quotes in the string

    test = "look at this string, the second string";

    using that as a delimiter would return the entire string above. (or error if you referred to the second position)