+ Start a Discussion
taaataaa 

Dont want last two digit, use of substring

Hi,

 

My Opp name is suppose "ABCD01", i want only "ABCD". How to get by using substring method.

 

Note: Opp name could be anything, not sure about the length. I want only last two numeric digit should be removed.

 

Thanx!

amidstcloudamidstcloud

First.. Use the String.Length() to find the length of the string . . then use the substring .. . 

String.substring(0,Length-2);

 

USe the other checks also . like . if (length > 2)  etc.. 

 

Thanks 

Ankit

taaataaa

hey, thanks

 

but one thing i didnt kept in my mind, number could be more then 3 digits as "ABCD123", that time it will return "ABCD1", but I want only string value, any idea?

amidstcloudamidstcloud

hey 

 

YOu can use the below approach but I would not say this is the best approach :- 

 

String s ;
int last;
int i = 1;
while (!isAlpha(s)){
   last = s.length - i; 
   s = s.substring(0,last); 
   i++;
}