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

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-表示空格字符。

希望您对代码有所帮助。

10-07 19:46
查看更多