字符串去除空白内容

           String id="                杭州税务助力企业复工复产进行时    ——聚 
焦“四力” 春风“速递”        ";
            String shortId=id.trim();
            String longId=id.replaceAll("\\s", "");
            System.out.print("[");
            System.out.print(shortId);
            System.out.println("]");

            System.out.println();

            System.out.print("[");
            System.out.print(longId);
            System.out.println("]");

去除字符串首尾的空白(trim());去除字符串中所有的空白内容(.replaceAll(\\s,"")

posted @ 2020-11-20 16:32  勤奋的园  阅读(333)  评论(0编辑  收藏  举报