I can receive data like:
232321 or dwd
But sometimes a "+" may appear between the Strings. How do I extract only what comes BEFORE this character?
If so, I have an entry like this: "432d + 321" I would stay: 432d.
I can receive data like:
232321 or dwd
But sometimes a "+" may appear between the Strings. How do I extract only what comes BEFORE this character?
If so, I have an entry like this: "432d + 321" I would stay: 432d.
String str = "432d+321";
String res = str.split("\+")[0];
// res = 432d.
Note: For meta caracteres
, you should use '\'
.
\ , ^ , $ , * , + , ?
Do this:
String str = "432d+321";
int posicao = str.indexOf('+');
if (posicao >= 0) {
str = str.substring(0, posicao);
}
System.out.println(str); // Imprime 432d