[英]HTML content to a string with regular expressions
我需要撰写电子邮件正文,并为每个用户添加用户名密码。 目前,我将html内容包含在字符串中,而我尝试使用字符串格式化程序来替换相应用户的用户名和密码。 我如何在单个字符串中包含html内容以及同时更改不同用户的映射时遇到麻烦。
代码片段
String regEmailBody =
"<div>
+ "successfully registered for the system. <br>Your username "
+ "is[@email_placeholder].<br>Your temporary password is <b>"
+ "@sysGeneratedPW_placeholder!</b><br>Please login to the system to reset your password, "
+ "click on the button below.<br></p></div>";
regEmailBody.replaceFirst("@name_placeholder", name);
regEmailBody.replaceAll("@userEmail", emailAdd);
Java中的字符串是不可变的。 在您的代码中,您正在生成带有替换部分的新字符串,但没有将它们存储在任何地方。
regEmailBody = regEmailBody.replaceFirst("@name_placeholder", name);
(示例代码在div之后也缺少“,并且占位符字符串与您要替换的内容不匹配。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.