Android String Replace replaceWordsAll(String src, String targetValue, String newValue)

Here you can find the source of replaceWordsAll(String src, String targetValue, String newValue)

Description

replace Words All

Declaration

public static String replaceWordsAll(String src, String targetValue,
            String newValue) 

Method Source Code

//package com.java2s;

public class Main {
    public static String replaceWordsAll(String src, String targetValue,
            String newValue) {/*ww  w .  ja  v a 2s  .  com*/
        if (targetValue.equals("")) {
            throw new IllegalArgumentException(
                    "Old pattern must have content.");
        }
        StringBuffer result = new StringBuffer();
        int startIdx = 0;
        int idxOld = 0;
        while ((idxOld = src.indexOf(targetValue, startIdx)) >= 0) {
            result.append(src.substring(startIdx, idxOld));
            result.append(newValue);
            startIdx = idxOld + targetValue.length();
        }
        result.append(src.substring(startIdx));
        return result.toString();
    }
}

Related

  1. replaceR(String str)
  2. replaceSpace(String str)
  3. replaceStr(String number)
  4. replaceString(String s, Map replacement)
  5. replaceWords(String src, String targetValue, String newValue)
  6. replaceBlank(String str)
  7. replaceBlank(String str)
  8. replaceBlank(String str)
  9. replaceBlank(String str)