Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

commas in a list surrounded by quotes

New Here ,
Aug 17, 2009 Aug 17, 2009

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?

1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 17, 2009 Aug 17, 2009

Try this:

delim = "','",

testoutput = listgetat(test,2,delim);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 17, 2009 Aug 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)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 17, 2009 Aug 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 17, 2009 Aug 17, 2009
LATEST

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>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources