unble to replace string
<p>This is my replace method  in java but unble to replace for following.</p>

<p>It replace only one \</p>

<p>Please help. If any body have any different method for replace?</p>

<p>I had tried java standard API but that is not working can please try following senario
--> System.out.println(replace("this%s is the problem" , "%" , "\%"));</p>

<pre><code>public static String replace(String str, String sub, String rep) {
        int s, p, q;
        int slen = sub.length();
        StringBuffer sb = new StringBuffer();

        s = 0;
        p = str.indexOf(sub);
        q = p + slen;
        while (p != -1) {
            sb.append(str.substring(s, p));
            sb.append(rep);
            s = q;
            p = str.indexOf(sub, s);
            if (p != -1) {
                q = p + slen;
            }
        }
        sb.append(str.substring(s));
        return sb.toString();
    }
</code></pre>
