java - 如何替换 String s = "33 6.33";在 Java 中为 "336.33"

标签 java string

这是一个奇怪的词;这是我的代码:

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/

相关文章:

java - ConcurrentHashMap<String, Ref> 与 AtomicReference<Map<String, Ref>>

java - 下一次出发地为 java

java - UnsupportedClassVersionError 异常阻止 Tomcat 启动

Python 字符串格式 : For loops?

java - Java 中创建字符串的时间

c++ - 将std::basic_string <Char>转换为字符串

java - 为什么我收到错误 "java.lang.ClassNotFoundException"?

java - 测试 char 是否为 int 时出现 ArrayIndexOutOfBounds

python - 你如何在 Python 中旋转一个字符串数组?

c++ - 在 C++ 中将字符串乘以 int