zoukankan      html  css  js  c++  java
  • java去除字符串中的空格、回车、换行符、制表符

    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    
    
    
    /**
     * @author lei
     * 2011-9-2
     */
    public class StringUtils {
    
        public static String replaceBlank(String str) {
            String dest = "";
            if (str!=null) {
                Pattern p = Pattern.compile("\s*|	|
    |
    ");
                Matcher m = p.matcher(str);
                dest = m.replaceAll("");
            }
            return dest;
        }
        public static void main(String[] args) {
            System.out.println(StringUtils.replaceBlank("just do it!"));
        }
        /*-----------------------------------
    
        笨方法:String s = "你要去除的字符串";
    
                1.去除空格:s = s.replace('\s','');
    
                2.去除回车:s = s.replace('
    ','');
    
        这样也可以把空格和回车去掉,其他也可以照这样做。
    
        注:
     回车(u000a) 
        	 水平制表符(u0009) 
        s 空格(u0008) 
        
     换行(u000d)*/
    }
  • 相关阅读:
    10.19
    10.17
    张钊的作业
    张钊的第十一份作业
    张钊的第十份作业
    张昭的第九次作业
    张钊的第八份作业
    张钊的第七份作业
    张钊的第六次作业啊
    张钊O的第五次作业
  • 原文地址:https://www.cnblogs.com/jh5240/p/3149047.html
Copyright © 2011-2022 走看看