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

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

Description

replace Words

Declaration

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

Method Source Code

//package com.java2s;

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

Related

  1. replaceKeyWords(StringBuilder sb, String[] keywords, String replaceStr)
  2. replaceR(String str)
  3. replaceSpace(String str)
  4. replaceStr(String number)
  5. replaceString(String s, Map replacement)
  6. replaceWordsAll(String src, String targetValue, String newValue)
  7. replaceBlank(String str)
  8. replaceBlank(String str)
  9. replaceBlank(String str)