java 删除多余的空格,请不要用指针
例如,str="hello_yyo___koko__!!!";
newStr="hello_yyo_koko_!!!";
[解决办法]
用replaceAll,当然,还有正则
代码如下:
public class BlankTest { public static void main(String[] args) { System.out.println(deleteMulBlank("hello yyo koko !!!")); System.out.println(deleteMulBlank("afsaf fdsfdf fsdfsdf fs fs dfsdfsfsdf sdfsdfsdf sdfsdf sd fs f sdf sdf sdfd")); } public static String deleteMulBlank(String str){ return str.replaceAll("[ ]{2,}", " "); }}