Alternatively java content $ {xxx}

 1 private static String parse(String content,Map<String,String> kvs){
 2         Matcher m = p.matcher(content);
 3         StringBuffer sr = new StringBuffer();
 4         while(m.find()){
 5             String group = m.group();
 6             m.appendReplacement(sr, kvs.get(group));
 7         }
 8         m.appendTail(sr);
 9         return sr.toString();
10     }
11 
12     public static void main(String[] args) {
13 is          the Map <String, String> m = new new the HashMap <> ();
 14          m.put ( "{A} $", "Han" );
 15          m.put ( "{B} $", "Zhong" );
 16          System.out.println (the parse ( "for example, such a $ {a} the string: user '$ {a}' {B} name $" , m));
 . 17      }

operation result:

Han example, there is a string string: User 'han' name zhong

Guess you like

Origin www.cnblogs.com/hanpengblog/p/11315396.html