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

Comma delimited list

Participant ,
Sep 17, 2009 Sep 17, 2009

Hi,

In the following list, how can I keep the word Social, Behavioral, and Economic Sciences as one word instead of

Social

Behavioral

and Economic Sciences

<cfloop list="Biological Sciences, Social, Behavioral, and Economic Sciences" index="i" delimiters=",">

<cfoutput> #i# <br /></cfoutput>

</cfloop>

The list should look like:

Biological Sciences

Social, Behavioral, and Economic Sciences

Thanks!

TOPICS
Getting started
1.6K
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

Valorous Hero , Sep 17, 2009 Sep 17, 2009

Use something other then a comma to delimit the list.

<cfloop list="Biological Science| Social, Behavioral, and Economic Sciences" index="i" delimiters="|">

<cfoutput> #i# <br /></cfoutput>

</cfloop>

Translate
Valorous Hero ,
Sep 17, 2009 Sep 17, 2009

Use something other then a comma to delimit the list.

<cfloop list="Biological Science| Social, Behavioral, and Economic Sciences" index="i" delimiters="|">

<cfoutput> #i# <br /></cfoutput>

</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
Participant ,
Sep 21, 2009 Sep 21, 2009
LATEST

Thanks Ian!  It worked great!

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
Community Expert ,
Sep 17, 2009 Sep 17, 2009

Assuming that you may not tamper with the given list, then there are functions you can use. For example, listFirst() and listRest().

<cfset list="Biological Sciences, Social, Behavioral, and Economic Sciences">
<cfoutput>#listFirst(list)#<br>
#listRest(list)#</cfoutput>

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 ,
Sep 17, 2009 Sep 17, 2009

The problem here is that it is impossible to distinguish between whether the comma is delimiter, or whether it is part of the data.  So using list functions will not reliably work unless one already knows the composition of the list.

If there is a chance there will be commas in the data, then one must use a different delimiter.  For user-entered data, then using any keyable character for the delimiter is ill-advised.

I tend to use chr(30) - record separator - as my delimiter, as it is very unlikely to appear in use-entered data.

That said, CF lists are a crap multi-value data structure, and I avoid them where I can; preferring to use an array, struct or object as appropriate.

--

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
Resources