Welcome!

Charlie Arehart

Subscribe to Charlie Arehart: eMailAlertsEmail Alerts
Get Charlie Arehart via: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn


Article

Testing Against Many Values in a CFIF

Testing Against Many Values in a CFIF

If you have to test a condition against many values in a CFIF, you may be tempted to write out a very long condition, such as:

CFIF FORM.STATE IS "MA" OR FORM.STATE IS "VT" FORM.STATE IS "AK" ...

This quickly becomes unwieldy. There is an alternative approach. Simply use the LISTFIND (or LISTFINDNOCASE) function instead, as in:

CFIF LISTFIND("MA,VT,AK",FORM.STATE)

Note that the list of values is specified first, then the value to search for in the list. Also, the LISTFIND function presumes you are using commas to separate list values, but if you need to test strings that contain commas, you can specify an alternate delimiter as the 3rd argument in the function.

Finally, be careful about the case (upper/lower) of both comparison strings. If the value of FORM.STATE were "ma", the condition would not be true. To cause the condition to ignore case, use LISTFINDNOCASE instead.

Charlie Arehart Education Director, Fig Leaf Software

More Stories By Charlie Arehart

A veteran ColdFusion developer since 1997, Charlie Arehart is a long-time contributor to the community and a recognized Adobe Community Expert. He's a certified Advanced CF Developer and Instructor for CF 4/5/6/7 and served as tech editor of CFDJ until 2003. Now an independent contractor (carehart.org) living in Alpharetta, GA, Charlie provides high-level troubleshooting/tuning assistance and training/mentoring for CF teams. He helps run the Online ColdFusion Meetup (coldfusionmeetup.com, an online CF user group), is a contributor to the CF8 WACK books by Ben Forta, and is frequently invited to speak at developer conferences and user groups worldwide.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.