Link to home
Start Free TrialLog in
Avatar of Coast Line
Coast LineFlag 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?
Avatar of Brijesh Chauhan
Brijesh Chauhan
Flag of India image

<cfset divTag = '1234'/>

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

<cfdump var="#divTag#">
SOLUTION
Avatar of Brijesh Chauhan
Brijesh Chauhan
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Coast Line

ASKER

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!

:(
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.  

@GD,

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...