Why I cannot get rid of whitespace before thousands?
I have written such method to check if string can be parse to double:
EDIT: OK, I've updated the method because everyone writes the same answer - this is unusual situation
public static boolean isNumber(String test) {
// remove whitespaces
System.out.print("Test is - " + test);
test = test.replaceAll("\\s", "");
// test = test.replaceAll("[ \\t]", "");
// test = test.replaceAll("\\s+", "");
// test = test.replaceAll(" ", "");
System.out.print(" - now test is - " + test);
// match pattern - numbers with decimal delimiter as dot or comma
String decimalPattern = "([0-9]*)(\\.|\\,)([0-9]*)";
boolean match = Pattern.matches(decimalPattern, test);
System.out.println(" - Is this number? ===> " + match);
return match;
}
And now I'm going insane. Here is some of outputs of my method:
[stdout] Test is - aasdfg - now test is - aasdfg - Is this number? ===> false
[stdout] Test is - aa sd fg - now test is - aasdfg - Is this number? ===> false
[stdout] Test is - 123.50 - now test is - 123.50 - Is this number? ===> true
[stdout] Test is - 123,50 - now test is - 123,50 - Is this number? ===> true
[stdout] Test is - 1 123.50 - now test is - 1 123.50 - Is this number? ===> false
The last line of the output is the strange one!
Advice - test value comes from HSSFCell#getStringCellValue()
- maybe here is problem. None of commented String#replaceAll
works.