Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have strings like

'dd-01-12'
'ads-03-387'

i want to get the last values after last '-' values

12 and 387.

I want to select numbers only from sqlite with select query.

What I have tried:

Please help me.
substr(accountno,3,4) 
Posted
Updated 31-Dec-17 0:59am

Use a regex:
(?<=-)\d+?$
Should do it.
 
Share this answer
 
Sample sub String code
String text="abc-01-001";        
String sub_text=text.substring(7);        
System.out.println(sub_text);

This will give "001" as the output.

But in your question two strings are not in same length so the substring will not give the correct answer to all strings. So it it better to use split method to get correct results. See below code sample,
String []splitArray=text.split("-");
String new_text=splitArray[2];        
System.out.println(new_text);

This will also give "001" as the output.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900