数千の前に空白を取り除くことができないのはなぜですか?
文字列を double に解析できるかどうかを確認するメソッドを作成しました。
編集:わかりました、誰もが同じ答えを書いているので、メソッドを更新しました-これは異常な状況です
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;
}
そして今、私は気が狂っています。これが私の方法の出力の一部です:
[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
出力の最後の行は奇妙なものです!
アドバイス - テスト値の由来HSSFCell#getStringCellValue()
- おそらくここに問題があります。コメントされString#replaceAll
た作品はありません。