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

Multiple Chr. Delimiters

Guest
Jun 19, 2006 Jun 19, 2006
Is there a way to use multiple characters as a delimiter? For instance:

<cfloop index="i" list="1 : 2 : 3 : 4" delimiters=" : "></cfloop>

If not -- how would you do this. We have data comming from a third party and it has some inconsistent data. If we can use multiple delimiters then it will solve the problem.
1.3K
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

correct answers 1 Correct answer

Deleted User
Jun 19, 2006 Jun 19, 2006
Thanks everyone -- got it!
Translate
Mentor ,
Jun 19, 2006 Jun 19, 2006
Per live docs at cfloop: looping over a list or file

You can put more than one character in the delimiters attribute, in any order. For example, this loop processes commas, colons, and slashes as list delimiters:

<cfloop index = "ListElement"
list = "John/Paul,George::Ringo"
delimiters = ",:/">
<cfoutput>#ListElement#</cfoutput><br>
</cfloop>


Phil
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
Guest
Jun 19, 2006 Jun 19, 2006
What if you need the delimiter to be " : "? Here is an example of the data we are dealing with:

Cards: US : Paper : Trash

"Cards: US is the first item. Not Cards and then US. There are only 3 items in this list NOT 4. If we use ":" as the delimiter it would appear to be 4 different items.
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
Engaged ,
Jun 19, 2006 Jun 19, 2006
You may want to use a different separator then, because a delimiter is a single character. You can define multiple delimiters for the command to look for, but the delimiter still has to be a single character.

We usually use the pipe (|) because it is a non-standard character that you won't find cropping up in everyday strings, like colons or commas do.

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 ,
Jun 19, 2006 Jun 19, 2006
> You can put more than one character in the delimiters attribute, in any
> order. For example, this loop processes commas, colons, and slashes as list
> delimiters:

I didn't take the requirement to mean "more than one delimiter", but to be
"one multi-character delimiter"..?

CF does not support multi-character delimiters natively. You can use the
Java split() method to split your list into an array, and then loop over
the array.

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#split(java.lang.String)

--
Adam
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 ,
Jun 19, 2006 Jun 19, 2006
<cfscript>
theList="1 : 2 : 3 : 4 : 5 : test:meElmo : duck:and:cover";
mcRegex="\s:\s";
pattern=createObject("java","java.util.regex.Pattern").compile(mcRegex);
parsedArray=pattern.split(theList);
</cfscript>

<cfdump var="#parsedArray#">
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
Guest
Jun 19, 2006 Jun 19, 2006
LATEST
Thanks everyone -- got it!
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