String 相关

一、去除空格,回车,换行符,制表符

// 去除空格,回车,换行符,制表符
public static String replaceBlank(String str) {
String dest = "";
if (str != null) {
Pattern p = Pattern.compile("\\s*|\t|\r|\n");
Matcher m = p.matcher(str);
dest = m.replaceAll("");
}
return dest;
}

 

二、分割字符串(用特殊字符)

  要用\\转义

String str = "aaa^|^bbb^|^ccc";

String[] split = str.split("\\^\\|\\^");

posted @ 2017-04-20 14:17  新宇泽起  阅读(134)  评论(0编辑  收藏  举报