利用正则替换空白字符

前端之家收集整理的这篇文章主要介绍了利用正则替换空白字符前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
private String replaceBlank(String s) {
  String result= null;
  if (s == null) { 
  return result; 
  } else {
    Pattern p = Pattern.compile("\\s*|\t|\r|\n");
    Matcher m = p.matcher(str); 
    result= m.replaceAll("");
    return result;
  }
}

去除字符串中所有的空白字符,包括空格、制表符、回车符等

猜你在找的正则表达式相关文章