I used to pass a order list to a some functions, but when i have a similar index, it return the wrong position example:
<cfset Listado=‘Customer_Id,Customer,Order_id,Order’>
<cfdump var=“#listcontains(Listado,‘Order’)#”>
I neet the last one, but id don’t work.
This returns an index of 3 for me, which is correct. As I am sure you are aware that cfml index’s start at 1 unlike almost every other language that start at 0.
function listContains(list, substring [, delimiters]): numeric
Determines the index of the first list element that contains a
specified substring.
Returns the index of the first list element that contains
substring. If not found, returns zero. The search for the substring is case-sensitive.
“Order_id” contains substring “Order”, so the answer is 3.
2 Likes
@eescovar is right.
You should use listFind()
1 Like
Yup. ListContains looks for any list element containing what you specify as a substring. ListFind looks for only the EXACT value you specify.
When people use ListContains as if it were ListFind, really nasty problems can occur in an application.
1 Like