Here you can find the source of replaceByMap(String tpl, Map
Parameter | Description |
---|---|
tpl | string like xxxx{key}yyy{key}zzzz |
map | a parameter |
public static String replaceByMap(String tpl, Map<String, Object> map)
//package com.java2s; //License from project: Apache License import java.util.Map; public class Main { public static String replaceByMap(String tpl, Map<String, Object> map) { if (tpl != null && map != null && map.size() > 0) { for (String key : map.keySet()) { tpl = tpl.replace("{" + key + "}", String.valueOf(map.get(key))); }/*www.j a va 2 s . c o m*/ } return tpl; } public static String replace(String tpl, Object... vals) { if (tpl != null) { for (int i = 1; i <= vals.length; i++) { tpl = tpl.replace("{?" + i + "}", String.valueOf(vals[i - 1])); } } return tpl; } }