Here you can find the source of replace(String source, String subject, String object)
public static String replace(String source, String subject, String object)
//package com.java2s; public class Main { public static String replace(String source, String subject, String object) {/* www .jav a2 s . co m*/ StringBuffer rtnStr = new StringBuffer(); String preStr = ""; String nextStr = source; String srcStr = source; while (srcStr.indexOf(subject) >= 0) { preStr = srcStr.substring(0, srcStr.indexOf(subject)); nextStr = srcStr.substring( srcStr.indexOf(subject) + subject.length(), srcStr.length()); srcStr = nextStr; rtnStr.append(preStr).append(object); } rtnStr.append(nextStr); return rtnStr.toString(); } public static int indexOf(String str, String searchStr) { if (str == null || searchStr == null) { return -1; } return str.indexOf(searchStr); } }