日期:2014-05-20 浏览次数:20643 次
public static void main(String[] args) throws Exception { String s = "113@ ere qqq yyui"; s=s.replaceAll("[^a-zA-Z 0-9]", ""); for (String str: s.split(" ")) { System.out.println(str); } //末尾标点是不是不要反转? s = "To be or not to be.";//"oT eb ro ton ot eb."。 StringBuffer sBuffer = new StringBuffer(); for (String str: s.split("\\s")) { char punctuate=' '; char[] chars = str.toCharArray(); for (int i = chars.length-1;i>=0;i--) { if (i==chars.length-1 && !Character.isLetter(chars[i])) { punctuate = chars[i]; continue; } sBuffer.append(chars[i]); } sBuffer.append(punctuate); } System.out.println(sBuffer); }