1 11 package org.eclipse.help.internal.base.util; 12 13 17 public class TString { 18 public static String change(String in, String oldPat, String newPat) { 20 if (oldPat.length() == 0) 21 return in; 22 if (oldPat.length() == 1 && newPat.length() == 1) 23 return in.replace(oldPat.charAt(0), newPat.charAt(0)); 24 if (in.indexOf(oldPat) < 0) 25 return in; 26 int lastIndex = 0; 27 int newIndex = 0; 28 StringBuffer newString = new StringBuffer (); 29 for (;;) { 30 newIndex = in.indexOf(oldPat, lastIndex); 31 if (newIndex != -1) { 32 newString.append(in.substring(lastIndex, newIndex) + newPat); 33 lastIndex = newIndex + oldPat.length(); 34 } else { 35 newString.append(in.substring(lastIndex)); 36 break; 37 } 38 } 39 return newString.toString(); 40 } 41 } 42 | Popular Tags |