Java Map Substitute substitute(String s, Map map)

Here you can find the source of substitute(String s, Map map)

Description

substitute

License

BSD License

Declaration

public static String substitute(String s, Map<String, String> map) 

Method Source Code

//package com.java2s;
//License from project: BSD License 

import java.util.Map;

public class Main {
    private static final String START_FLAG = "${";
    private static final String END_FLAG = "}";

    public static String substitute(String s, Map<String, String> map) {
        StringBuilder ret = new StringBuilder(s.length());
        int pos = 0;
        for (int start, end; (start = s.indexOf(START_FLAG, pos)) != -1
                && (end = s.indexOf(END_FLAG, start)) != -1;) {
            ret.append(s.substring(pos, start)).append(map.get(s.substring(start + START_FLAG.length(), end)));
            pos = end + END_FLAG.length();
        }//ww  w . j av  a 2 s.co  m
        ret.append(s.substring(pos, s.length()));
        return ret.toString();
    }
}

Related

  1. subsituteAttr(Map attrMap, String text)
  2. substitute(String aString, Map variablesValues, String open, String close)
  3. substitute(String page, String payRef, String name, String emailAddress, String when, String license, Map map)
  4. substitute(String s, Map map)
  5. substitute(String str, Map subs)
  6. substitute(String str, Map subs)
  7. substituteExpressionLanguage(String stringToParse, Map variableMap)
  8. substituteForTokens(String input, Map tokenMap, boolean invertMap)