bit of a weird one this as I have checked it over multiple times and still cannot see anything wrong with what I am doing.
Anyway, I have this string named score that is a method parameter. The input is "0 - 2"
, I would like to parse this string but before I must remove the blank spaces. I've tried using score = score.replaceAll("\\s+", "")
and score = score.replace(" ", "")
however the blank spaces are still not replaced. Underneath this line of code I print out the score and it is still displaying the string as "0 - 2"
with the spaces not deleted. Any help would be much appreciated.
Here is the code for the method
public static int parseScore(String score, boolean first){
score = score.replaceAll("\\s+",""); // remove white space
System.out.println(score);
String[] tokens = score.split("-");
if(first == true){
return Integer.parseInt(tokens[0]);
}else{
return Integer.parseInt(tokens[1]);
}
}
Error:
Exception in thread "main" java.lang.NumberFormatException: For input string: "0 " at java.lang.NumberFormatException.forInputString(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at PredictResult2.parseScore(PredictResult2.java:32) at PredictResult2.main(PredictResult2.java:102)
EDIT:
Forgot to mention that the string that I am using has already been parsed from a downloaded html page. Could that have anything to do with it? maybe different character formatting or something?