@@ -0,0 +1,2131 @@
+package com.artbeatte.exercises.strings;%0A%0A/**%0A * @author art.beatte%0A * @version 3/16/16%0A */%0Apublic class SubStringReplace %7B%0A%0A    /* non-instantiable class */%0A    private SubStringReplace() %7B %7D%0A%0A    public static char%5B%5D replace(char%5B%5D string, char%5B%5D target, char%5B%5D replacement) %7B%0A        if (string == null %7C%7C target == null %7C%7C replacement == null %7C%7C string.length == 0 %7C%7C string.length %3C target.length) %7B%0A            return string;%0A        %7D%0A%0A        int wordDifference = replacement.length - target.length;%0A%0A        int sInd = 0;%0A        while (sInd %3C string.length) %7B%0A            if (indexStartsWord(string, sInd, target)) %7B%0A                string = replaceWord(string, sInd, replacement, wordDifference);%0A                sInd += replacement.length;%0A            %7D else %7B%0A                sInd++;%0A            %7D%0A        %7D%0A%0A        return string;%0A    %7D%0A%0A    private static boolean indexStartsWord(char%5B%5D string, int sInd, char%5B%5D target) %7B%0A        boolean isWord = (string.length - sInd) %3E= target.length;%0A%0A        for (int tInd = 0; isWord && tInd %3C target.length; tInd++) %7B%0A            isWord = string%5BsInd%5D == target%5BtInd%5D;%0A            sInd++;%0A        %7D%0A%0A        return isWord;%0A    %7D%0A%0A    private static char%5B%5D replaceWord(char%5B%5D string, int sInd, char%5B%5D replacement, int wordDifference) %7B%0A        char%5B%5D ret = string;%0A        if (wordDifference %3C 0) %7B%0A            // shrink array%0A            ret = new char%5Bstring.length - wordDifference%5D;%0A        %7D else if (wordDifference %3E 0) %7B%0A            // grow array%0A            ret = new char%5Bstring.length + wordDifference%5D;%0A        %7D%0A%0A        // optimization: this will iterate over the entire array even when it's the same size. TODO%0A        int rInd = 0;%0A        for (int i = 0; i %3C ret.length; i++) %7B%0A            if (i %3C sInd) %7B%0A                // copy head%0A                ret%5Bi%5D = string%5Bi%5D;%0A            %7D else if (i %3E= sInd + replacement.length) %7B%0A                // copy tail%0A                ret%5Bi%5D = string%5Bi - wordDifference%5D;%0A            %7D else %7B%0A                // replacement%0A                ret%5Bi%5D = replacement%5BrInd++%5D;%0A            %7D%0A        %7D%0A%0A        return ret;%0A    %7D%0A%7D%0A

Work done in < 45minutes.