September 19th, 2003, 03:06 PM
cfloop list doesn't return null values
I have a list like ",89,90,,87". When I use cfloop go to through it, I only get 3 values instead of 5 with 2 nulls. How do I specify the <cfloop> tag to return 5?
I want to have something like this:
Instead, I get this:
Thanks in advance for any help!
September 21st, 2003, 08:43 PM
The unfortunate answer is there is no way to get CFLOOP to do this on its own. CF treats multiple null delimiters as one delimiter, which is a benefit in some situations and a pain in the butt in others. You could either send the string in with spaces between the delimiters, or run a replace function that adds a space after each delimiter, but then you must remember to trim() the value when you use it, like this:
<cfset list = "1,2,3,,5,,,,9,10">
<cfset counter = 0>
<cfloop index="thisElement" list="#replace( list, ',', ', ', 'All' )#" delimiters=",">
<cfset counter = counter + 1>
Element #counter#: #trim( thisElement )#<br>
A custom tag or function could also handle this pretty easily.
September 22nd, 2003, 12:31 PM
Thanks for the tip!