String s = "this is a good idea";
// 去除多个空格
String str1 = s.replaceAll(" +", " ");
// str1 = "this is a good idea"
String str2 = s.replaceAll("\\s{1,}", " ");
// str2 = "this is a good idea"
String str3 = s.replaceAll("\\s+", " ");
// str3 = "this is a good idea"
java把字符串内多个空格转化为一个空格
最新推荐文章于 2022-11-29 17:35:09 发布