Solved

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

Posted on 2011-03-17
6
545 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
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Having an issue with NumberFormat 7 62
How to do a Left Outer Join sql query in coldfusion 4 121
Coldfusion scheduled tasks as one task 2 93
Comparing 2 Lists Coldfusion 8 58
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…
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

730 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