Discuss / Java / Homework

Homework

Topic source

0刘俊铖

#1 Created at ... [Delete] [Delete and Lock User]
static String replaceByMap(String source, Map<String, String> rule) {    Pattern p = Pattern.compile("\\$\\{[a-zA-Z]+}");    Matcher matcher = p.matcher(source);    StringBuilder s = new StringBuilder();    while (matcher.find()){        String temp = source.substring(matcher.start(),matcher.end());        matcher.appendReplacement(s,rule.get(temp.substring(2,temp.length()-1)));    }    return s.toString();}

0刘俊铖

#2 Created at ... [Delete] [Delete and Lock User]
static String replaceByMap(String source, Map<String, String> rule) {    Pattern p = Pattern.compile("\\$\\{[a-zA-Z]+}");    Matcher matcher = p.matcher(source);    StringBuilder s = new StringBuilder();    while (matcher.find()){        String temp = source.substring(matcher.start(),matcher.end());        matcher.appendReplacement(s,rule.get(temp.substring(2,temp.length()-1)));    }    return s.toString();}

  • 1

Reply