Reputation: 2613
I have a string with a format like "integer1_text integer2"
(ex. "23_home 2" ).
I would like to remove the integer1, or replace it with an empty string (so keep only "home 2").
Integer1 is a number from 0 to 1000 and i just want to remove it.
I have tryed to do something like string=mystring.replaceAll("[^0-9]+"_","");
but is not working correctly.
Any idea please? thanks
Upvotes: 0
Views: 85
Reputation: 444
There are just a few small mistakes in your regex, try:
mystring.replaceAll("^[0-9]+_", "");
Upvotes: 1
Reputation: 157437
you can use indexOf("_");
Returns the index within this string of the first occurrence of the specified character.
and use substringIint startIndex, int endIndex);
to extract the String you need, with startIndex
the index returned by indexOf
Upvotes: 1