Here you can find the source of replaceVariable(final String src, final Map
public static String replaceVariable(final String src, final Map<String, String> value)
//package com.java2s; import java.util.Map; public class Main { public static String replaceVariable(final String src, final Map<String, String> value) { int len = src.length(); StringBuffer buf = new StringBuffer(len); for (int i = 0; i < len; i++) { char c = src.charAt(i); if (c == '$') { i++;/*from w w w . j a v a 2 s .co m*/ StringBuffer key = new StringBuffer(); char temp = src.charAt(i); while (temp != '}') { if (temp != '{') { key.append(temp); } i++; temp = src.charAt(i); } String variable = value.get(key.toString()); if (null == variable) { buf.append(""); } else { buf.append(variable); } } else { buf.append(c); } } return buf.toString(); } }