我有下面的字符串
string = "Book Your Domain And Get\n \n\n \n \n \n Online Today."
string = str.replace("\\s","").trim();
哪个返回
str = "Book Your Domain And Get Online Today."
但是想要的是
str = "Book Your Domain And Get Online Today."
我试过许多正则表达式,也用谷歌搜索但没有成功。并没有找到相关问题,请帮忙,非常感谢
最佳答案
使用 \\s+
而不是 \\s
因为您的输入中有两个或多个连续的空格。
string = str.replaceAll("\\s+"," ")
关于java - 如何删除字符串之间的空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18870395/