Coldfusion ListContains() VS ListFind()

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,

Description
Determines the index of the first list element that contains a specified substring.
Returns
Index of the first list element that contains substring. If not found, returns zero.

Adobe Documentation

To explain the problem I ran into I’m gonna use this page I found, explaining a similar situation as mine.

ListContains issue

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

 

UPDATE 10/05/2010

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.

Description

Converts a one-dimensional array to a list.

Returns

Delimited list, as a string.

Adobe Documentation

Becareful on that, because even it’s clear on the documentation, I over-looked it and ran into a problem.

Advertisements
Coldfusion ListContains() VS ListFind()

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s