I'm having an array of strings (phone numbers) and i need to remove +, which is in front of one of the elements (numbers) since it throws an NumberFormatException when i try to cast it to int.
The elements in array are 0888888888 0888123456 +359886001122 and i have already used .split(" ") in order to separate them. I've also tried .split(" +") in order to remove + from the last one, but this didn't work.
You have to use replaceAll instead of split, for example :
"0888888888 0888123456 +359886001122".replaceAll("\\+", "");
this will show you :
0888888888 0888123456 359886001122
//-------------------^------------
Then if you want to split each number you can use split(" ") like this :
String numbers[] = "0888888888 0888123456 +359886001122".replaceAll("\\+", "").split(" ");
System.out.println(Arrays.toString(numbers));
this will give you :
[0888888888, 0888123456, 359886001122]
EDIT
Or like @shmosel said in comment you ca use replace("+", "")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With