Strip trailing, or repeated, delimiters in a CF list

Found a helpful trick at http://stackoverflow.com/questions/182455/coldfusion-and-trailing-comma –
if you want to clean up a list in ColdFusion, take advantage of the fact that CF list functions ignore empty elements. ListChangeDelims() consequently strips off that last “element”.


var cleanList = ListChangeDelims(DirtyList, ",", ",");

For example, I often need this when building an url or file path, especially when a base path is configurable and may or may not have a trailing slash, and depending how the dynamic path is built, it may or not end up with another trailing slash. E.g.,


var pathSeparator = createObject("java","java.io.File").separator;
var path = ListChangeDelims(listAppend(getConfigBean().getProperty('path_base_directory'), "subdir", pathSeparator), pathSeparator, pathSeparator);

No Comments

Leave a Reply

Your email is never shared.Required fields are marked *