java 去掉字符串右侧空格

public static String rightTrim(String str) {
    String regex = "(.*\\S+)(\\s+$)";
    Pattern p = Pattern.compile(regex);
    Matcher m = p.matcher(str);
    if (m.matches()) {
       str = m.group(1);
    }
  return str;
 }

posted @ 2013-07-17 11:36  李小加  阅读(1309)  评论(0编辑  收藏  举报