Using Apache commons string substitutor, StrSubstitutor


import org.apache.commons.lang.text.StrSubstitutor;

Map map = new HashMap();
map.put("DAYS", "2");
map.put("HOURS", "8");
String str = "${DAYS} days and ${HOURS} hours to go";

StrSubstitutor sub = new StrSubstitutor(map);
String resolvedString = sub.replace(str);

0 comments: