现在的位置: 首页 > 综合 > 正文

日文系统下全角和半角空格trim

2012年08月14日 ⁄ 综合 ⁄ 共 398字 ⁄ 字号 评论关闭

   public static void main(String[] args) throws MalformedPatternException {
        System.out.println("  a b c ".trim());
        deleteFullSpace("  a b c ");
    }

   private static void deleteFullSpace(String testStr) {
       // ^[ *| *]*"表示以全角空格或半角空格开始的所有集合
       // [ *| *]*$"表示以全角空格或半角空格结尾的所有集合
       String resultStr = testStr.replaceAll("^[ *| *]*", "").replaceAll("[ *| *]*$", "");
       System.out.println("|" + resultStr + "|");
   }
 

抱歉!评论已关闭.