to be honest I was thrilled the day I found coldfusion list functions. I was like, there is so much I can do with all these.
But the other day, I ran into a problem. (In a way, I am glad this happen, becase debugging would have been a nightmare.)
Coldfusion documentation states ListContains() as,
Determines the index of the first list element that contains a specified substring.
Index of the first list element that contains substring. If not found, returns zero.
To explain the problem I ran into I’m gonna use this page I found, explaining a similar situation as mine.
in anycase above link didn’t work, I’m taking the essence of it.
what it’s is, if you have a list 1,2,3,4,55,6, and if you use ListContains(ListName, "5", ",") you would expect to get 0, because "5" in NOT in mylist.
But what does the function returns, 5 because by documentation definition "5" is in "55" (substring).
what? I know it’s confusing, you and me both, but that’s how ListContains() work.
So what’s the solution, ListFind() or[ListFindNoCase() , depending on content of your List].
But be careful now to give the result you want, make sure to match up EXACTLY as it is in the list, including leading and trailing spaces.
To be in the safe side, whereever you appen your list, make sure to use trim() to avoid unnecessary spaces.
I have to find out this the hard way, but now you don’t have to.
Glad to help, you are welcome. lol
Even though I didn’t mention ArrayToList() function here thought of dropping a word on that. Come to find out, ArrayToList() only works for one-dimentional arrays.
Converts a one-dimensional array to a list.
Delimited list, as a string.
Becareful on that, because even it’s clear on the documentation, I over-looked it and ran into a problem.