Java tutorial
//package com.java2s; import java.util.Map; public class Main { public static String replace(String xml, Map value) { int len = xml.length(); StringBuffer buf = new StringBuffer(len); for (int i = 0; i < len; i++) { char c = xml.charAt(i); if (c == '$') { i++; StringBuffer key = new StringBuffer(); char temp = xml.charAt(i); while (temp != '}') { if (temp != '{') { key.append(temp); } i++; temp = xml.charAt(i); } String variable = (String) value.get(key.toString()); if (null == variable) { buf.append(""); } else { buf.append(variable); } } else { buf.append(c); } } return buf.toString(); } }