Android String Replace replace(String from, String to, String source)

Here you can find the source of replace(String from, String to, String source)

Description

replace

Declaration

public static String replace(String from, String to, String source) 

Method Source Code

//package com.java2s;

public class Main {
    public static String replace(String from, String to, String source) {
        if (source == null || source.length() == 0 || from == null
                || from.length() == 0 || to == null) {
            return source;
        }//from   w  w w .  j  ava2  s  .  c  o  m
        StringBuffer str = new StringBuffer("");
        int index = -1;
        int len = from.length();
        while ((index = source.indexOf(from)) != -1) {
            str.append(source.substring(0, index) + to);
            source = source.substring(index + len);
        }
        str.append(source);
        return str.toString();
    }
}

Related

  1. replace(String line, String oldString, String newString)
  2. replace(String originalString, String searchString, String replaceString)
  3. replace(String str, Map replacementMap)
  4. replace(final String text, final String fromText, final String toText)