java正则表达式替换空格和换行符


  1. public class StringUtil {   
  2.     public static String getStringNoBlank(String str) {   
  3.         if(str!=null && !"".equals(str)) {   
  4.             Pattern p = Pattern.compile("\\s*|\t|\r|\n");   
  5.             Matcher m = p.matcher(str);   
  6.             String strNoBlank = m.replaceAll("");   
  7.             return strNoBlank;   
  8.         }else {   
  9.             return str;   
  10.         }        
  11.     }   


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM