String delimiter = "\\*\\*";
String html = "<html><head></head><body>**USERNAME** AND **PASSWORD**</body></html>";
Map<String, String> mp = new HashMap<String, String>();
mp.put("USERNAME", "User A");
mp.put("PASSWORD", "B");
for (Entry<String, String> entry : mp.entrySet()) {
html.replace(delimiter + entry.getKey()+ delimiter, entry.getValue());
}
That should usually replace those both strings, but it does not. Does anyone has an idea?
String is immutable, which means that the html reference doesn't change, rather the replace method returns a new String object that you have to assign.
html = html.replace(delimiter + entry.getKey()+ delimiter, entry.getValue());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With