这是一个奇怪的词;这是我的代码:
public static void main(String[] args) {
String s = "33 6.33";
Pattern p = Pattern.compile("\\s*|\t|\r|\n");
Matcher m = p.matcher(s);
s = m.replaceAll("");
System.out.println(s);
}
但它不起作用。
我找到了为什么代码不起作用,空白是不间断的空格....
最佳答案
s.replaceAll("\\s+","");
//to remove multiple spaces even if you give more than 1 space it will do the job.
s - 表示空格字符。
希望代码对您有所帮助。
关于java - 如何替换 String s = "33 6.33";在 Java 中为 "336.33",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36006727/