java替换字符ITeye - AG环亚娱乐集团

java替换字符ITeye

2019-01-09 16:38:52 | 作者: 冰蝶 | 标签: | 浏览: 2949

private static final String[] searchList; private static final String[] replacementList; private static final Map String, String specialCharactorMap = Maps.newHashMap(); static { specialCharactorMap.put("?", ""); specialCharactorMap.put("?", ""); specialCharactorMap.put(":", "_"); specialCharactorMap.put(":", "_"); specialCharactorMap.put("“", ""); specialCharactorMap.put("”", ""); specialCharactorMap.put("\"", ""); specialCharactorMap.put("!", ""); specialCharactorMap.put("¥", ""); specialCharactorMap.put("……", ""); specialCharactorMap.put(";", ""); specialCharactorMap.put("(", "("); specialCharactorMap.put(")", ")"); specialCharactorMap.put(",", "_"); specialCharactorMap.put("。", ""); specialCharactorMap.put("、", ""); specialCharactorMap.put("/", "_"); specialCharactorMap.put("\\", "_"); specialCharactorMap.put(" ", "_"); specialCharactorMap.put("__", "_"); List String searchs = Lists.newArrayList(); List String replacements = Lists.newArrayList(); specialCharactorMap.entrySet().forEach(entry - { searchs.add(entry.getKey()); replacements.add(entry.getValue()); searchList = searchs.toArray(new String[] {}); replacementList = replacements.toArray(new String[] {}); * @param args * @author kanpiaoxue * Create Time 2018年 上午8:39:10 public static void main(String[] args) { String str = " h?。、??ello/world "; String rs = StringUtils.replaceEachRepeatedly(str.trim(), searchList, replacementList); System.out.println(rs);// hello_world

 

版权声明
本文来源于网络,版权归原作者所有,其内容与观点不代表AG环亚娱乐集团立场。转载文章仅为传播更有价值的信息,如采编人员采编有误或者版权原因,请与我们联系,我们核实后立即修改或删除。

猜您喜欢的文章