Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c#将占位符匹配到text.html并替换_C#_Html_String_List_Replace - Fatal编程技术网

c#将占位符匹配到text.html并替换

c#将占位符匹配到text.html并替换,c#,html,string,list,replace,C#,Html,String,List,Replace,我在Visual Studio c#中构建的应用程序遇到了一个小问题。我有一个WebBrowser,它在你发送电子邮件之前会显示一封预览电子邮件,我正在尝试使用字符串替换在预览窗口中自动设置电子邮件的一些详细信息 EmailTemplateConfigClass具有公共列表get和set属性 public List<HeaderFooterReplacement> HeaderFooterReplacements { get; set; } 然后使用if条件将占位符与预设html电

我在Visual Studio c#中构建的应用程序遇到了一个小问题。我有一个WebBrowser,它在你发送电子邮件之前会显示一封预览电子邮件,我正在尝试使用字符串替换在预览窗口中自动设置电子邮件的一些详细信息

EmailTemplateConfigClass具有公共列表get和set属性

public List<HeaderFooterReplacement> HeaderFooterReplacements { get; set; }
然后使用if条件将占位符与预设html电子邮件模板匹配,在电子邮件中找到相同的文本,并使用(.replace)将其替换为值

最后,在替换完成后,我将web浏览器预览文本设置为html,没有控制台错误,并且在调试模式下一切正常,除了预览电子邮件时,它仍然显示占位符,例如电子邮件标题

有什么想法吗?此外,如果你需要澄清任何事情,请询问

谢谢你排好队

if (headerFooterContents == HeaderFooterReplacement.Placeholder)
您正在将整个内容与占位符进行比较。另外,
Replace
返回字符串,并且不替换原始字符串中的值,您必须再次分配
headerFooterContents
。您的
foreach
循环应该是这样的:

foreach (var HeaderFooterReplacement in EmailTemplateConfig)
{
    if (headerFooterContents.Contains(HeaderFooterReplacement.Placeholder))
    {
        headerFooterContents = headerFooterContents.Replace(HeaderFooterReplacement.Placeholder, HeaderFooterReplacement.Value);
    }
}
if (headerFooterContents == HeaderFooterReplacement.Placeholder)
foreach (var HeaderFooterReplacement in EmailTemplateConfig)
{
    if (headerFooterContents.Contains(HeaderFooterReplacement.Placeholder))
    {
        headerFooterContents = headerFooterContents.Replace(HeaderFooterReplacement.Placeholder, HeaderFooterReplacement.Value);
    }
}