Search code examples
coldfusioncfmlcoldfusion-11

How to specify delimiter for list.each function in ColdFusion 11?


I have adopted the CFScript syntax for most of the work with ColdFusion now, since with the new version of ColdFusion v11(codenamed Splender), almost all the short-comings of the script style syntax has been given serious thoughts. Thought suprisingly, I came across a requirement where I needed to iterate throught the list with variable delimiter. So I choose the list.each function in CF11 and not any other option would do since I also need the current index value along the way as well.

list.each(function(element,index,list){
    writeOutput("#index#:#element#;");
}, ";")

The problem is that this function surprisingly does not seem to support a custom delimiter. To save the time, I would like to mention that I already tried the for (element in...) with a count variable for my needs.

var idx=1;
for (element in "a,b,c,d,e"){
    writeOutput(element);
    LOCAL.idx++;
}

But I would appreciate some help with the original list.each function in CF11, is it even possible somehow to implement? or is it what I think a shortcoming.


Solution

  • I'm not using CF11, but i would point you to this bug report, which seems to say the HF3 does exactly what you want.

    If that doesn't work, or in the meantime, you could convert it to an array and use ArrayEach().