java去除字符串中的空格、回车、换行符、制表符 .

 /**
  * 去除字符串中所包含的空格(包括:空格(全角,半角)、制表符、换页符等)
  * @param s
  * @return
  */
 public static String removeAllBlank(String s){
  String result = "";
  if(null!=s && !"".equals(s)){
   result = s.replaceAll("[ *| *| *|//s*]*", "");
  }
  return result;
 }
 
 /**
  * 去除字符串中头部和尾部所包含的空格(包括:空格(全角,半角)、制表符、换页符等)
  * @param s
  * @return
  */
 public static String trim(String s){
  String result = "";
  if(null!=s && !"".equals(s)){
   result = s.replaceAll("^[ *| *| *|//s*]*", "").replaceAll("[ *| *| *|//s*]*$", "");
  }
  return result;
 }

你可能感兴趣的:(java)