?
Solved

Delete First Two Characters from string?

Posted on 2007-10-01
7
Medium Priority
?
5,571 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
0
Comment
Question by:Westside2004
7 Comments
 
LVL 52

Expert Comment

by:_agx_
ID: 19995045
One way is to use list functions

<cfset theValue ="c_2">
<cfoutput>#listRest(theValue, "_")#</cfoutput>
0
 
LVL 4

Accepted Solution

by:
Russell2566 earned 1000 total points
ID: 19995798
My prefered:
        listLast(String, '_')

Also Works:
        RemoveChars(String, 1, 2)
0
 
LVL 52

Expert Comment

by:_agx_
ID: 19995905
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.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 9

Expert Comment

by:digicidal
ID: 19996744
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 ...
}
0
 
LVL 25

Expert Comment

by:James Rodgers
ID: 19998217
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
0
 
LVL 25

Expert Comment

by:James Rodgers
ID: 19998270
or if you want to remove everything to the left of teh first digit

#rereplace(str,"^[^[:digit:]]","","All")#
0
 
LVL 52

Expert Comment

by:_agx_
ID: 20002972
> Any help appreciated.

You're welcome ;-)
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month17 days, 2 hours left to enroll

864 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