Coldfusion Comma Delimited Lists - adding a space after comma

I have a variable submitted in a form... #form.selectedOrgs#. This can be one item or multiple. It is already a comma delimited list when it is submitted. For example:

#form.selectedOrgs# would be org1,org2,org3,org4

I don't know how to insert a space between the items in the list. Any help would be greatly appreciated!
traportAsked:
Who is Participating?
 
gdemariaCommented:

use the listChangeDelims function to change the list from comma delimited to comma + space

#listChangeDelims(form.selectedOrgs,", ")#


0
 
Brijesh ChauhanStaff IT EngineerCommented:
how do you need the list to be ? org1 ,org2 , org3 ??
0
 
Brijesh ChauhanStaff IT EngineerCommented:
you can just use the replace function ...

<cfset testList = 'org1,org2,org3,org4'>
<cfset newList = replace(testList,',',' ,','ALL')>
<cfoutput> #newList#</cfoutput>

Open in new window


if you want the space after the comma, then

<cfset testList = 'org1,org2,org3,org4'>
<cfset newList = replace(testList,',',', ','ALL')>
<cfoutput> #newList#</cfoutput>

Open in new window

0
 
traportAuthor Commented:
Both worked perfectly. I went w/ the last one gdemaria - I hadn't heard of the listChange function. Thanks to you both.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.