StrSubspublic class StrSubs extends Object A few String functions that are missing from String |
Methods Summary |
---|
public static void | main(java.lang.String[] args)A simple main for testing
System.out.println(
subst("lazy", "supine", "A quick bronze fox lept a lazy bovine"));
System.out.println(
subst("$DIR", "/home/ian", "$DIR/xxx"));
| public static java.lang.String | subst(java.lang.String oldStr, java.lang.String newStr, java.lang.String inString)Replace oldstr with newstr in instring
int start = inString.indexOf(oldStr);
if (start == -1) {
return inString;
}
StringBuffer sb = new StringBuffer();
sb.append(inString.substring(0, start));
sb.append(newStr);
sb.append(inString.substring(start+oldStr.length()));
return sb.toString();
|
|