search

Home  >  Q&A  >  body text

JAVA 正则表达式匹配空格或换行符

巴扎黑巴扎黑2925 days ago422

reply all(1)I'll reply

  • 怪我咯

    怪我咯2017-04-18 10:44:44

    Try this

    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    public class c_170222 {
        public static String getStringNoBlank(String str) {      
            if(str!=null && !"".equals(str)) {      
                Pattern p = Pattern.compile("\s*|\t|\r|\n");      
                Matcher m = p.matcher(str);      
                String strNoBlank = m.replaceAll("");      
                return strNoBlank;      
            }else {      
                return str;      
            }           
        } 
     }       

    reply
    0
  • Cancelreply