Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

cfif, listLast, need to find a char at the end of a variable

Posted on 2011-03-17
6
539 Views
Last Modified: 2012-05-11
i'm looping through a list and outputting variables like so:

<cfloop list="#ColList#" index="ColList">
<cfoutput>#ColList#</cfoutput>
</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
0
Comment
Question by:bede123
  • 4
  • 2
6 Comments
 
LVL 52

Expert Comment

by:_agx_
ID: 35161328
First, make sure you use different variables name for  the "list" and "index". Then assuming the values always contain

<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>
0
 
LVL 52

Expert Comment

by:_agx_
ID: 35161383
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
0
 
LVL 1

Author Comment

by:bede123
ID: 35161403
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! :-)
0
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 35161457
I chose to create a separate variable named "suffix" for readability.  But technically you could just use the listLast() function twice.

  <cfif listLast(theItem, "_") eq "1">
         it's 1. do something
    <cfelseif listLast(theItem, "_") eq "2">
         it's 2. do something else
     <cfelse>
          not 1 or 2. do something else
     </cfif>
0
 
LVL 1

Author Comment

by:bede123
ID: 35164887
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
0
 
LVL 52

Expert Comment

by:_agx_
ID: 35166715
Welcome :)
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question