Copy link to clipboard
Copied
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!
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>
Copy link to clipboard
Copied
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>
Copy link to clipboard
Copied
Thanks Ian! It worked great!
Copy link to clipboard
Copied
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>
Copy link to clipboard
Copied
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