Coldfusion Comma Delimited Lists - adding a space after comma

Posted on 2011-04-20
Last Modified: 2012-05-11
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!
Question by:traport
    LVL 11

    Expert Comment

    by:Brijesh Chauhan
    how do you need the list to be ? org1 ,org2 , org3 ??
    LVL 11

    Assisted Solution

    by:Brijesh Chauhan
    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

    LVL 39

    Accepted Solution


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

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


    Author Closing Comment

    Both worked perfectly. I went w/ the last one gdemaria - I hadn't heard of the listChange function. Thanks to you both.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them ( . I did keep the main js functions but made sever…
    Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
    Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
    This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now