Solved

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

Posted on 2011-03-17
6
525 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_
Comment Utility
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_
Comment Utility
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
Comment Utility
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 your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
Comment Utility
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
Comment Utility
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_
Comment Utility
Welcome :)
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now