I have some strings that begin with a number and a whitespace and I want to extract everything after that whitespace.
First string:
1 abc def
What I want:
abd def
Second string:
1 23 abs
What I want:
23 abs
What is the best way to do it in Java? I know it can be achieved by regular expressions and String methods, but which way is the shortest?
str = str.replaceFirst("^[0-9]+ ", "");
Try it like this
String str = "1 abc def";
String split[] = str.split(" ", 2);
System.out.println(split[1]);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.