简体   繁体   English

HTML内容转换为带有正则表达式的字符串

[英]HTML content to a string with regular expressions

I need to compose an email body and have user name password atributes to be added of every user to it. 我需要撰写电子邮件正文,并为每个用户添加用户名密码。 For now i have the html content in a string and im trying to have string formatter to replace the user name and password for the respective user. 目前,我将html内容包含在字符串中,而我尝试使用字符串格式化程序来替换相应用户的用户名和密码。 How ever I am having trouble having the html content in a single string and also get the mapping of diferent users to be changed accordingly. 我如何在单个字符串中包含html内容以及同时更改不同用户的映射时遇到麻烦。

code snipet 代码片段

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); 

Strings in java are immutable. Java中的字符串是不可变的。 In your code, you are producing new strings with replaced parts, but you are not storing them anywhere. 在您的代码中,您正在生成带有替换部分的新字符串,但没有将它们存储在任何地方。

regEmailBody = regEmailBody.replaceFirst("@name_placeholder", name);

(the example code are also missing a " after the div, and the placeholder strings does not correspond with what you're trying to replace.) (示例代码在div之后也缺少“,并且占位符字符串与您要替换的内容不匹配。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM