@@ -0,0 +1,990 @@
+package algo.string;%0A%0A/**%0A * Created by sherxon on 4/20/17.%0A */%0Apublic class ReplaceString %7B%0A    public static void main(String%5B%5D args) %7B%0A        System.out.println(replaceAll(%22x%2520x%2520%22, %22%252%22, %22c%22));%0A    %7D%0A    static String replaceAll(String s, String s1, String s2)%7B%0A        StringBuilder sb= new StringBuilder();%0A        char%5B%5D a= s.toCharArray();%0A        for (int i = 0; i %3C a.length; i++) %7B%0A            char current=a%5Bi%5D;%0A            if(current!=s1.charAt(0))%7B%0A                sb.append(current);%0A                continue;%0A            %7D%0A            int j = 0;%0A            for (; j %3C s1.length(); j++) %7B%0A                if(i+j %3E= a.length %7C%7C  s1.charAt(j) != a%5Bi+j%5D)%7B%0A                    break;%0A                %7D%0A            %7D%0A            if(j==s1.length())%7B // contains substring%0A                sb.append(s2);%0A                i+=s1.length()-1;%0A            %7Delse%7B%0A                sb.append(current); // need to add current%0A            %7D%0A        %7D%0A        return sb.toString();%0A    %7D%0A%7D%0A

replace string problem and solution