问题描述
怎样实现如下的输入输出呢?input:onezerooutput:01input:zeroonezerooutput:010input:zeroonezerooutput:010inputzer/oon/ezero!output010intpurzero,one,zerooutput010
解决方案
解决方案二:
解决方案三:
正则。
解决方案四:
或许能给你一些帮助publicclassStringUtil{privatestaticHashMap<String,String>config(){HashMap<String,String>result=newHashMap<String,String>();result.put("zero","0");result.put("one","1");result.put("two","2");result.put("three","3");result.put("four","4");result.put("five","5");result.put("six","6");result.put("seven","7");result.put("eight","8");result.put("nine","9");returnresult;}privatestaticStringinit(Stringstr){Stringresult=str;result=result.replaceAll("[^\w]","");returnresult;}publicstaticStringgetNum(Stringstr){Stringresult=init(str);HashMap<String,String>map=config();Set<String>set=map.keySet();for(Strings:set){result=result.replaceAll(s,map.get(s));}returnresult;}publicstaticvoidmain(String[]args){System.out.println(StringUtil.getNum("one/zero/one"));}}