Here you can find the source of substitute(String txt, String pattern, String sub)
public static String substitute(String txt, String pattern, String sub)
//package com.java2s; //License from project: Open Source License public class Main { public static String substitute(String txt, String pattern, String sub) { int o = 0; for (;;) { o = txt.indexOf(pattern, o); if (o < 0) break; txt = txt.substring(0, o) + sub + txt.substring(o + pattern.length()); o += sub.length();//from w ww . j a v a2 s . c o m } return txt; } public static int indexOf(String str, String[] patt) { return indexOf(str, patt, 0); } public static int indexOf(String str, String[] patt, int start) { int best = -1; for (int i = 0; i < patt.length; i++) { int o = str.indexOf(patt[i], start); if ((o >= 0) && ((best == -1) || (o < best))) best = o; } return best; } }