iberck
11/17/2015 - 1:19 PM

String replace

String replace

import java.util.HashMap;
import java.util.Map;

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

public class StringReplaceTest {

  /**
   * @param args
   */
  public static void main(String[] args) {
      
    Map<String, String> valueMap = new HashMap<String, String>();
    valueMap.put("state", "Andhra Pradesh");
    valueMap.put("capital", "Hyderabad");
    
    String varPrefix = "${";
    String varSuffix = "}";
    String template = "The capital of ${state} is ${capital}";
    System.out.println(StrSubstitutor.replace(template, valueMap, varPrefix, varSuffix));
  }

}