gpt4 book ai didi

vb.net - 为什么我不能对 IO.File.ReadAllText() 字符串执行 String.Replace() 操作?

转载 作者:行者123 更新时间:2023-12-02 12:35:52 24 4
gpt4 key购买 nike

我正在使用 System.IO.FIle.ReadAllText() 获取我为电子邮件内容创建的一些模板文件的内容。然后我想对文件中的某些标记进行替换,以便我可以将动态内容添加到模板中。

这是我的代码,在我看来它应该可以正常工作......

Dim confirmUrl As String = Request.ApplicationPath & "?v=" & reg.AuthKey
Dim text As String = IO.File.ReadAllText( _
ConfigurationManager.AppSettings("sign_up_confirm_email_text").Replace("~", _
Request.PhysicalApplicationPath))
Dim html As String = IO.File.ReadAllText( _
ConfigurationManager.AppSettings("sign_up_confirm_email_html").Replace("~", _
Request.PhysicalApplicationPath))

text.Replace("%%LINK%%", confirmUrl)
text.Replace("%%NAME%%", person.fname)

html.Replace("%%LINK%%", confirmUrl)
html.Replace("%%NAME%%", person.fname)

由于某种原因,我无法使 %%LINK%% 和 %%NAME%% Replace() 调用正常工作。我检查了一下是否与编码相关,所以我将每个文件设置为UTF-8。并且还使用了 ReadAllText(String, Encoding) 的强制编码重载,但仍然没有骰子。有什么想法吗?

最佳答案

问题在于 .NET 中的字符串是不可变的。因此您的替换代码应如下所示:

text = text.Replace("%%LINK%%", confirmUrl);
text = text.Replace("%%NAME%%", person.fname);

html = html.Replace("%%LINK%%", confirmUrl);
html = html.Replace("%%NAME%%", person.fname);

关于vb.net - 为什么我不能对 IO.File.ReadAllText() 字符串执行 String.Replace() 操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1112553/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com