String Manipulation

T

TheVooDooChild

I have an alpha-numeric string. If the 1st position is non-numeric, I
need to remove it. For some reason this is causing me difficulty. Can
someone show me a way to do this? Example: "R123456789" I want
"123456789"

Thanks.
 
F

Fahd Shariff

String s = "R123456789" ;

//get first char
char c = s.charAt(0) ;

//is it non-numeric?
if(!Character.isDigit(c)){
//remove it
s = s.substring(1,s.length());
}
 
L

Lisa

Fahd Shariff said:
String s = "R123456789" ;

//get first char
char c = s.charAt(0) ;

//is it non-numeric?
if(!Character.isDigit(c)){
//remove it
s = s.substring(1,s.length());
}

you can use "s = s.substring(1);"
instead of specifying the length explicitly
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top