Java String Substritute substituteToken(StringBuffer buf, String token, String value)

Here you can find the source of substituteToken(StringBuffer buf, String token, String value)

Description

substitute Token

License

Open Source License

Declaration

public static void substituteToken(StringBuffer buf, String token, String value) 

Method Source Code

//package com.java2s;
/*/*from w  w w . j  a  va2  s . com*/
 * This file is subject to the license found in LICENCE.TXT in the root directory of the project.
 * 
 * version 1.4
 */

public class Main {
    public static String substituteToken(String pattern, String token, String value) {
        StringBuffer buf = new StringBuffer(pattern);
        substituteToken(buf, token, value);
        return buf.toString();
    }

    public static void substituteToken(StringBuffer buf, String token, String value) {
        String from = getTokenString(token);
        int fromLength = from.length();
        for (int index = buf.indexOf(from); index != -1; index = buf.indexOf(from, index)) {
            buf.replace(index, index + fromLength, value);
        }
    }

    public static String getTokenString(String token) {
        return "[" + token + "]";
    }
}

Related

  1. substituteSubString(String input, String find, String replace)
  2. substituteSymbol(String text, String symbol, String value)
  3. substituteSymbol(String text, String symbol, String value)
  4. substituteTabsAndNewLinesWithSpaces(String str)
  5. substituteText(String text, String token, String substitute)
  6. substituteUserId(final long aUserId, final String aTemplate)
  7. substituteVars(String text, char[] names, Object[] values)
  8. substituteWhenEmpty(Object value, String valueWhenEmpty)