public static void replaceAll ( StringBuffer haystack , String needle , String newNeedle ) { /* if(needle == null || "".equals(needle)) { throw new IllegalArgumentException("string to replace may not be empty"); } int idx = haystack.indexOf(needle); int needleLength = needle.length(); int newNeedleLength = newNeedle.length(); while (idx != -1) { haystack.replace(idx, idx + needleLength, newNeedle); idx = haystack.indexOf(needle, idx + newNeedleLength); }*/ replaceAll ( haystack , needle , newNeedle , 0 ) ; }
replaces all occurrences of needle in haystack with newNeedle the input itself is not modified