public class StringUtil {
public static void replaceBlank()
{
Pattern p = Pattern.compile(“\s*| ||\n”);
String str="I am a, I am Hello ok, new line ffdsa!";
System.out.println("before:"+str);
Matcher m = p.matcher(str);
String after = m.replaceAll("");
System.out.println("after:"+after);
}
public static void main(String[] args) {
replaceBlank();
}
}
-----------------------------------
笨方法:String s = "你要去除的字符串";
1.去除空格:s = s.replace('\s','');
评论0
最新资源