Heys guys!
I'm having difficulties replacing string which consists of special characters.
So I have a following string for example:
Dear *|customer_name|*,
thank you for your order *|order_id|*.
Please expect delivery *|delivery_date|*
What I would like to to is to replace those dynamic variables with values.
I've done this snippet of code but it doesn't replace them correctly:
Map<String, String> structMap = getContectMap();
for (String key : structMap.keySet()) {
if (bodyText.contains(key)) {
bodyText.replaceAll(getVariableKey(key), structMap.get(key));
}
}
private String getVariableKey(Object key) {
return "\\*|" + key + "|\\*";
}
This is the ouput I get:
Dear User|User|User,
thank you for your order 1236|1236|1236.
Please expect delivery 5.12.2017|5.12.2017|5.12.2017
Any ideas what I'm doing wrong?
*EDIT* Found a problem. I should escape pipe character (|) too, works now.