I have a question about the strsubstitutor with double $$ varible, I have the following code:
Map<String, Object> params = new HashMap<String, Object>();
params.put("hello", "hello");
String templateString = "The ${hello} $${test}.";
StrSubstitutor sub = new StrSubstitutor(params);
String resolvedString = sub.replace(templateString);
System.out.println(resolvedString);
The output is hello ${test}
If the test variable is with double $, and it can not be replaced, why the output is ${test}? Should not be still $${test}?
The reason why
$${test}becomes${test}is that${...}is a reserved keyword forStrSubstitutorand adding an extra$in front of it is used to escape it (i.e. if you want to get a literal${...}in output).Given that, the documentation says that by default
setPreserveEscapesis set tofalseand this means that:So if you want
$${test}in output you should setsetPreserveEscapes(true)before replacing the variables.