public static void main(String[] args) { String str ="45aBc+de.==fg,@hd"; String re = "[^A-Za-z]"; String result = str; for (String split: str.split(re)){ if (split!=null && split.length()!=0) { String reverse = new StringBuffer(split).reverse().toString(); result = result.replace(split,reverse); } } System.out.println(result); //45cBa+ed.==gf,@dh }
字符串单词反转其他顺序不变
最新推荐文章于 2022-08-08 21:58:07 发布