Apache commons lang의 StrSubstitutor 클래스를 이용한다.
(commons-lang 2.2 부터 지원)
Map valuesMap = new HashMap();
valuesMap.put("animal", "quick brown fox");
valuesMap.put("target", "lazy dog");
String templateString = "The ${animal} jumped over the ${target}.";
StrSubstitutor sub = new StrSubstitutor(valuesMap);
String resolvedString = sub.replace(templateString);
결과(resolvedString) : The quick brown fox jumped over the lazy dog.
http://commons.apache.org/proper/commons-lang/javadocs/api-2.6/index.html?org/apache/commons/lang/StringUtils.html
댓글 없음:
댓글 쓰기