第十一题
- 功能描述:已知:yi er san si wu liu qi ba jiu 分别对应123456789,
- 对一段只含有这几种字符串的字符串进行转换,如:
- 输入:yiersansan
- 输出:1233
/**
* 功能描述:已知:yi er san si wu liu qi ba jiu 分别对应123456789,
* 对一段只含有这几种字符串的字符串进行转换,如:
* 输入:yiersansan
* 输出:1233
* @author lx
*
*/
public class Test {
public static final String[] REGEX = {"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
public static void main(String[] args) {
System.out.println(new Test05().replace("yiersansan"));
}
/**
* 有9个对应关系,所以循环9次可全部替换完成
* @param str
* @return
*/
public String replace(String str) {
for (int i = 0; i < 9; i++) {
str = str.replace(REGEX[i], i + "");
}
return str;
}
}