private static String replace(String line, String oldString,
                                 String newString, boolean ignoreCase, int[] count) {
        if (line == null) {
            return null;
        }
        String lcLine = ignoreCase ? line.toLowerCase() : line;
        String lcOldString = ignoreCase ? oldString.toLowerCase() : oldString;
        int i = 0;
        if ((i = lcLine.indexOf(lcOldString, i)) >= 0) {
            int counter = 1;
            char[] line2 = line.toCharArray();
            char[] newString2 = newString.toCharArray();
            int oLength = oldString.length();
            StringBuilder buf = new StringBuilder(line2.length);
            buf.append(line2, 0, i).append(newString2);
            i += oLength;
            int j = i;
            while ((i = lcLine.indexOf(lcOldString, i)) > 0) {
                counter++;
                buf.append(line2, j, i - j).append(newString2);
                i += oLength;
                j = i;
            }
            buf.append(line2, j, line2.length - j);
            count[0] = counter;
            return buf.toString();
        }
        return line;
    }
Replaces all instances of oldString with newString in line.
The count Integer is updated with number of replaces.

@param line the String to search to perform replacements on.
@param oldString the String that should be replaced by newString.
@param newString the String that will replace all instances of oldString.
@param count a single element array that, after running, will contain the number of matching items
@return a String will all instances of oldString replaced by newString.
xmppserver/src/main/java/org/jivesoftware/util/StringUtils.java