Java String Substritute substitute(String txt, String pattern, String sub)

Here you can find the source of substitute(String txt, String pattern, String sub)

Description

substitute

License

Open Source License

Declaration

public static String substitute(String txt, String pattern, String sub) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String substitute(String txt, String pattern, String sub) {
        int o = 0;
        for (;;) {
            o = txt.indexOf(pattern, o);
            if (o < 0)
                break;
            txt = txt.substring(0, o) + sub + txt.substring(o + pattern.length());
            o += sub.length();//from  w ww  . j  a v  a2  s  . c  o  m
        }
        return txt;
    }

    public static int indexOf(String str, String[] patt) {
        return indexOf(str, patt, 0);
    }

    public static int indexOf(String str, String[] patt, int start) {
        int best = -1;
        for (int i = 0; i < patt.length; i++) {
            int o = str.indexOf(patt[i], start);
            if ((o >= 0) && ((best == -1) || (o < best)))
                best = o;
        }
        return best;
    }
}

Related

  1. substitute(String str, String source, String target)
  2. substitute(String str, String variable, String value, int num)
  3. substitute(String string, String pattern, String replacement)
  4. substitute(String strSource, String strValue, String strBookmark)
  5. substitute(String template, String[] values)
  6. substituteAll(String regexp, String subst, String target)
  7. substituteBlanks(String s, String subst)
  8. substituteCommandLine(String[] parsedCommandLine, String file1Name, String file2Name, String display1, String display2)
  9. substituteEnvironmentVariables(String str, String prefix, String suffix)