Android String Replace stringReplace(String str, String what, String replacement)

Here you can find the source of stringReplace(String str, String what, String replacement)

Description

string Replace

License

Open Source License

Declaration

public static String stringReplace(String str, String what,
            String replacement) 

Method Source Code

//package com.java2s;

public class Main {
    public static String stringReplace(String str, String what,
            String replacement) {
        int i = str.indexOf(what);

        if (i >= 0) {
            int j = 0;
            int whatLen = what.length();
            StringBuilder result = new StringBuilder();

            do {//  ww w.j av a  2s.  com
                result.append(str.substring(j, i));
                result.append(replacement);

                j = i + whatLen;
                i = str.indexOf(what, j);
            } while (i >= 0);

            result.append(str.substring(j));

            return result.toString();
        } else {
            return str;
        }
    }
}

Related

  1. replace(String source, CharSequence target, CharSequence replacement)
  2. replaceChar(String source, String subject, String object)
  3. replaceSpaceCharacter(String string)
  4. collapse(String str, String chars, String replacement)
  5. collapseControlChars(String str, String replacement)