What\'s the best way to remove the first word from a string in Java?
If I have
String originalString = \"This is a string\";
I want to r
This will definitely a good solution
String originalString = "This is a string";
originalString =originalString.replaceFirst("This ", "");
String str = "This is a string";
String str2=str.substring(str.indexOf(" "));
String str3=str.replaceFirst(str2, "");
String's replaceFirst and substring
also you can use this solution:
static String substringer(String inputString, String remove) {
if (inputString.substring(0, remove.length()).equalsIgnoreCase(remove)) {
return inputString.substring(remove.length()).trim();
}
else {
return inputString.trim();
}
}
Example : substringer("This is a string", "This");