We help IT Professionals succeed at work.

New podcast episode! Our very own Community Manager, Rob Jurd, gives his insight on the value of an online community. Listen Now!

x

Delete First Two Characters from string?

Westside2004
Westside2004 asked
on
5,608 Views
Last Modified: 2013-12-24
Hi,

How can I delete the first two characters from this string.

c_2
c_25
c_20

I want to just be left with the numeric part of the string.  Or everything to the right of the underscore

Any help appreciated.

-ws
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2015

Commented:
One way is to use list functions

<cfset theValue ="c_2">
<cfoutput>#listRest(theValue, "_")#</cfoutput>
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Most Valuable Expert 2015

Commented:
If the string only contains one underscore then ListLast() is equivalent to ListRest().  If it contains multiple underscores like "c_20_85"  the results would be:

listRest = 20_85
listLast = 85

String functions also work, but you they will throw an error if the string doesn't match that pattern for some reason.  So you should add error handling.
Alternately you could simply use this:
newvalue=right(mystring,Len(mystring)-2)

Of course this assume that the prefix is alway present and always 2 characters.  You might also want to provide some error handling like:
if (Len(mystring) GT 2) {
     newvalue=right(mystring,Len(mystring)-2)
     } else {
     ... Error handling here ...
}
James RodgersWeb Applications Developer
CERTIFIED EXPERT

Commented:
or
#rereplace(str,"[^[:digit:]]","","All")#

doesnt care an\bout length or even if there is no char in the string, just replaces any non digit, in fron, at teh end or in the middle
James RodgersWeb Applications Developer
CERTIFIED EXPERT

Commented:
or if you want to remove everything to the left of teh first digit

#rereplace(str,"^[^[:digit:]]","","All")#
CERTIFIED EXPERT
Most Valuable Expert 2015

Commented:
> Any help appreciated.

You're welcome ;-)
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.