Android String Replace replaceChar(String source, String subject, String object)

Here you can find the source of replaceChar(String source, String subject, String object)

Description

replace Char

Declaration

public static String replaceChar(String source, String subject,
        String object) 

Method Source Code

//package com.java2s;

public class Main {

    public static String replaceChar(String source, String subject,
            String object) {/*from  w ww  .  j ava2s  .  c o  m*/
        StringBuffer rtnStr = new StringBuffer();
        String preStr = "";
        String nextStr = source;
        String srcStr = source;

        char chA;

        for (int i = 0; i < subject.length(); i++) {
            chA = subject.charAt(i);

            if (srcStr.indexOf(chA) >= 0) {
                preStr = srcStr.substring(0, srcStr.indexOf(chA));
                nextStr = srcStr.substring(srcStr.indexOf(chA) + 1,
                        srcStr.length());
                srcStr = rtnStr.append(preStr).append(object)
                        .append(nextStr).toString();
            }
        }

        return srcStr;
    }

    public static int indexOf(String str, String searchStr) {
        if (str == null || searchStr == null) {
            return -1;
        }
        return str.indexOf(searchStr);
    }
}

Related

  1. removeIllegal(String input)
  2. replace(String s, String[] oldSubs, char[] newSubs)
  3. replace(String s, char oldSub, String newSub)
  4. replace(String s, char oldSub, char newSub)
  5. replace(String source, CharSequence target, CharSequence replacement)
  6. replaceSpaceCharacter(String string)
  7. collapse(String str, String chars, String replacement)
  8. collapseControlChars(String str, String replacement)
  9. stringReplace(String str, String what, String replacement)