Skip to main content
Inspiring
May 25, 2014
Answered

listtoarray with no value between delimiter

  • May 25, 2014
  • 1 reply
  • 831 views

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 has been closed for replies.
    Correct answer plarts

    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.

    1 reply

    BKBK
    Community Expert
    Community Expert
    May 26, 2014

    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?

    plartsAuthor
    Inspiring
    May 26, 2014

    My version of CF is 9.0.2

    Thanks,

    Pierre.

    BKBK
    Community Expert
    Community Expert
    May 26, 2014

    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">