Here you can find the source of replaceChar(String source, String subject, String object)
public static String replaceChar(String source, String subject, String object)
//package com.java2s; public class Main { public static String replaceChar(String source, String subject, String object) {/*from w ww . j ava2s . c o m*/ StringBuffer rtnStr = new StringBuffer(); String preStr = ""; String nextStr = source; String srcStr = source; char chA; for (int i = 0; i < subject.length(); i++) { chA = subject.charAt(i); if (srcStr.indexOf(chA) >= 0) { preStr = srcStr.substring(0, srcStr.indexOf(chA)); nextStr = srcStr.substring(srcStr.indexOf(chA) + 1, srcStr.length()); srcStr = rtnStr.append(preStr).append(object) .append(nextStr).toString(); } } return srcStr; } public static int indexOf(String str, String searchStr) { if (str == null || searchStr == null) { return -1; } return str.indexOf(searchStr); } }