Avatar of Coast Line
Coast Line
Flag for Canada asked on

Get the 3rd from the variable

Really a Noob Question, its been 38 hrs i am awake! i m unable to find a solution to this silly question

here it is

<cfset divtag = "1234">

everytime the value is coming, it will be four characters, they are not goingt o exceed, wanna extract the 3rd one and then on the basis of the 3rd element, i have a switch case staement for this

any idea?
ColdFusion Language

Avatar of undefined
Last Comment
Brijesh Chauhan

8/22/2022 - Mon
Brijesh Chauhan

<cfset divTag = '1234'/>

<cfset divTag = left(Right(divTag,2),1) />

<cfdump var="#divTag#">
Brijesh Chauhan

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Coast Line

Yeah! My Friend, Still working on different issues and i really do not know how much more time i have to to be awake, living right now on Coffee!

Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.

not for points..

Rick's use of mid() is the ideal solution.  It will handle any string 3 or more characters in length.

Using a combination of right() and left() functions will require the string to be exactly 4 characters.  I know you said it SHOULD always be 4 characters, but if it ever changes, you don't have to modify your code if you're using the mid() function.  

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Brijesh Chauhan


It is also possible that if the LENGHT changes then the author would need the second last element (say if it is 5 lenth, then he needs the 4th element), so left(), right() will give him the second last element.

So let's not DISCUSS on what can a function do or what it cannot and try to justify it, both solution would work for the author requirement...