Zac123
asked on
cfif, listLast, need to find a char at the end of a variable
i'm looping through a list and outputting variables like so:
<cfloop list="#ColList#" index="ColList">
<cfoutput>#ColList#</cfout put>
</cfloop>
each variable which is outputted ends with either _1 or _2
what i need is this:
CFIF variable ends in _1
THEN do this
IF it ends in _2
THEN do this
otherwise just do this.
thats the plain english version. :-) can anyone helpo me do this?
thanks
<cfloop list="#ColList#" index="ColList">
<cfoutput>#ColList#</cfout
</cfloop>
each variable which is outputted ends with either _1 or _2
what i need is this:
CFIF variable ends in _1
THEN do this
IF it ends in _2
THEN do this
otherwise just do this.
thats the plain english version. :-) can anyone helpo me do this?
thanks
Oops, posted too soon. I meant to say: assuming the values always contain a "_", then use the code above. Otherwise, you might want to add validation of the listLen
ASKER
That's perfect thanks. I can ensure that _ does exist by validating a couple of steps prior to this one.
I've been trying all night to put this together! I didn't even have Suffix in my version! :-)
I've been trying all night to put this together! I didn't even have Suffix in my version! :-)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
oh i see, i thought.... oh never mind.... so much to learn!
i decided to use the one without the suffix.
many thanks (again)
z
i decided to use the one without the suffix.
many thanks (again)
z
Welcome :)
<cfloop list="#ColList#" index="theItem">
<cfset suffix = listLast(theItem, "_")>
<cfif suffix eq "1">
it's 1. do something
<cfelseif suffix eq "2">
it's 2. do something else
<cfelse>
not 1 or 2. do something else
</cfif>
</cfloop>