str.trim(); //去掉首尾空格
str.replace(" “,”"); //去除所有空格,包括首尾、中间
str.replaceAll(" “, “”); //去掉所有空格,包括首尾、中间
str.replaceAll(” +",""); //去掉所有空格,包括首尾、中间
str.replaceAll("\s*", “”); //可以替换大部分空白字符, 不限于空格 ;
Java中去除字符串中空格的方法
最新推荐文章于 2024-06-12 19:04:51 发布
str.trim(); //去掉首尾空格
str.replace(" “,”"); //去除所有空格,包括首尾、中间
str.replaceAll(" “, “”); //去掉所有空格,包括首尾、中间
str.replaceAll(” +",""); //去掉所有空格,包括首尾、中间
str.replaceAll("\s*", “”); //可以替换大部分空白字符, 不限于空格 ;