Here you can find the source of replaceWordsAll(String src, String targetValue, String newValue)
public static String replaceWordsAll(String src, String targetValue, String newValue)
//package com.java2s; public class Main { public static String replaceWordsAll(String src, String targetValue, String newValue) {/*ww w . ja v a 2s . com*/ if (targetValue.equals("")) { throw new IllegalArgumentException( "Old pattern must have content."); } StringBuffer result = new StringBuffer(); int startIdx = 0; int idxOld = 0; while ((idxOld = src.indexOf(targetValue, startIdx)) >= 0) { result.append(src.substring(startIdx, idxOld)); result.append(newValue); startIdx = idxOld + targetValue.length(); } result.append(src.substring(startIdx)); return result.toString(); } }