ListToArray()
Copies the elements of a list to an array.
ListToArray( list=string, delimiter=string, includeEmptyFields=boolean, multiCharacterDelimiter=boolean );
Returns: Array
Examples
Simple example for listToArray function: Uses the listToArray() function to retrieve a list as an array
list = "red,green,orange";
getArray = listToArray(list);
someJSON = serializeJSON(getArray);
writeOutput(someJSON);
Expected Result: ["red", "green", "orange"]
Example for listToArray function with delimiter: Uses the listToArray() function with a semicolon delimiter to retrieve a list as an array
list = "coldfusion;php;java;sql";
getArray = listToArray(list,";");
someJSON = serializeJSON(getArray);
writeOutput(someJSON);
Expected Result: ["coldfusion", "php", "java", "sql"]
Example for listToArray function with includeEmptyFields: If includeEmptyFields is true, empty value add in array elements
list = "coldfusion;php;;java;sql";
getArray = listToArray(list,";",true);
someJSON = serializeJSON(getArray);
writeOutput(someJSON);
Expected Result: ["coldfusion", "php", " ", "java", "sql"]
Example for listToArray function with multiCharacterDelimiter: Uses the listToArray() function to retrieve a list as an array with multiCharacterDelimiter
list = "coldfusion,php,|test,java,|sql";
getArray = listToArray(list,",|",false,true);
someJSON = serializeJSON(getArray);
writeOutput(someJSON
);
Expected Result: ["coldfusion,php", "test,java", "sql"]
See also
- Lists
- Strings
- Arrays
- string.listToArray()
- Search Issue Tracker
- Search Lucee Test Cases (good for further, detailed examples)