Android String Sub String Get replace(String source, String subject, String object)

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

Description

replace

Declaration

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

Method Source Code

//package com.java2s;

public class Main {

    public static String replace(String source, String subject,
            String object) {/* www  .jav  a2 s  . co  m*/
        StringBuffer rtnStr = new StringBuffer();
        String preStr = "";
        String nextStr = source;
        String srcStr = source;

        while (srcStr.indexOf(subject) >= 0) {
            preStr = srcStr.substring(0, srcStr.indexOf(subject));
            nextStr = srcStr.substring(
                    srcStr.indexOf(subject) + subject.length(),
                    srcStr.length());
            srcStr = nextStr;
            rtnStr.append(preStr).append(object);
        }
        rtnStr.append(nextStr);
        return rtnStr.toString();
    }

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

Related

  1. unicodePreservingSubstring(String str, int begin)
  2. substringAfter(String str, String separator)
  3. substringBetween(String str, String open, String close)
  4. subStringEndString(String sourceStr, String endString)
  5. hightLinghtString(String destStr, String subStr, int color)
  6. replaceOnce(String source, String subject, String object)
  7. substring(String str, int toCount)
  8. substring(String str, int len, String more)
  9. substringFromLast(final String str, final String separator)