Skip to main content
Inspiring
May 25, 2014 8:54 PM UTC
Answered

listtoarray with no value between delimiter

Reading lines in a text file,

Listing a text file , with value between ;

sometime , there is no data between 2 ; which I need to know.

In that case, (when there is no value between the delimiter) my array have a different length (smaller)

Then the data order is not good.

As I want to save in a DataBase, I do not know what data in what field number ?

Thanks for any help,

Pierre.

    This topic is closed to new replies. Start a new post to keep the conversation going.
    plartsCorrect answer
    Inspiring
    May 27, 2014 11:55 AM UTC

    In ColdFusion 9, the third argument of the function listToArray, includeEmptyFields, instructs ColdFusion whether or not to include blank list elements. A demo follows:

    <cfset list = "a;b;;c;;;d">

    <!--- Include blank list elements --->

    <cfset array1 = listToArray(list,";",true)>

    <cfdump var="#array1#" label="Include blank list elements">

    <br>

    <!--- Exclude blank list elements --->

    <cfset array2 = listToArray(list,";",false)>

    <cfdump var="#array2#" label="Exclude blank list elements">


    Thanks a lot,

    I stopped at CF8 doc,

    I did not think that old functions have been improved.

    Great.

    Pierre.

    5 replies

    BKBK
    Community Expert
    Community Expert
    May 26, 2014 6:31 AM UTC

    Do you mean that you want to express "a;b;;c;;;d" as a list of 7 elements. If so, then the best solution depends on your ColdFusion version. Recent versions take account of missing list elements between delimiters. What is your version?

    Translate
    plartsAuthor
    Inspiring
    May 26, 2014 10:17 AM UTC

    My version of CF is 9.0.2

    Thanks,

    Pierre.

    Translate
    BKBK
    Community Expert
    Community Expert
    May 26, 2014 7:04 PM UTC

    In ColdFusion 9, the third argument of the function listToArray, includeEmptyFields, instructs ColdFusion whether or not to include blank list elements. A demo follows:

    <cfset list = "a;b;;c;;;d">

    <!--- Include blank list elements --->

    <cfset array1 = listToArray(list,";",true)>

    <cfdump var="#array1#" label="Include blank list elements">

    <br>

    <!--- Exclude blank list elements --->

    <cfset array2 = listToArray(list,";",false)>

    <cfdump var="#array2#" label="Exclude blank list elements">

    Translate