Here you can find the source of translate(String str, String searchChars, String replaceChars)
static String translate(String str, String searchChars, String replaceChars)
//package com.java2s; /*//from www.j av a2 s . c o m * Copied from CharSetUtils (commons lang) under Apache License http://www.apache.org/licenses/LICENSE-2.0 */ public class Main { static String translate(String str, String searchChars, String replaceChars) { if (str == null || str.length() == 0) { return str; } StringBuffer buffer = new StringBuffer(str.length()); char[] chrs = str.toCharArray(); char[] withChrs = replaceChars.toCharArray(); int sz = chrs.length; int withMax = replaceChars.length() - 1; for (int i = 0; i < sz; i++) { int idx = searchChars.indexOf(chrs[i]); if (idx != -1) { if (idx > withMax) { idx = withMax; } buffer.append(withChrs[idx]); } else { buffer.append(chrs[i]); } } return buffer.toString(); } }