사용자 도구

사이트 도구


java:string_format

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
java:string_format [2019/02/22 20:20]
kwon37xi
java:string_format [2019/02/22 20:27]
kwon37xi
줄 1: 줄 1:
 ====== Java String Format ====== ====== Java String Format ======
  
-====== String.format() ======+===== String.format() =====
   * [[https://dzone.com/articles/java-string-format-examples|Java String Format Examples]]   * [[https://dzone.com/articles/java-string-format-examples|Java String Format Examples]]
  
줄 54: 줄 54:
 </code> </code>
  
 +===== org.apache.commons.lang.text.StrSubstitutor =====
 +  * [[https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/text/StrSubstitutor.html|StrSubstitutor (Apache Commons Lang)]]
 +  * ''$'' escape -> ''$$''
 +<code java>
 +// 시스템 프라퍼티
 +StrSubstitutor.replaceSystemProperties(
 +    "You are running with java.version = ${java.version} and os.name = ${os.name}.");
 +    
 +// 일반적인 사용법
 +Map valuesMap = 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);
 +
 +// 결과
 +The quick brown fox jumped over the lazy dog.
 +</code>
  
java/string_format.txt · 마지막으로 수정됨: 2019/02/22 20:27 저자 kwon37xi