我正在使用System.Net.Mail,我正在将html读入电子邮件正文。
不幸的是,撇号字符'
显示为带黑色背景的问号。
我试图用html '
替换撇号,但这仍然显示带有黑色背景的问号。其他Html标签(h1,p等)工作正常。
我现在必须有一个非常明显的答案,但我似乎无法找到它。谢谢你的帮助。
更新
似乎是System.IO.StreamReader导致了我的问题。
using (StreamReader reader = new StreamReader("/Email/Welcome.htm"))
{
body = reader.ReadToEnd();
//body string now has odd question mark character instead of apostrophe.
}
答案 0 :(得分:2)
如果您知道文件的encoding,则需要将其传递给StreamReader
初始化:
using (StreamReader reader = new StreamReader("/Email/Welcome.htm", "Windows-1252"))
{
body = reader.ReadToEnd();
// If the encoding is correct you'll now see ´ rather than �
// Which, by the way is the unicode replacement character
// See: http://www.fileformat.info/info/unicode/char/fffd/index.htm
}
答案 1 :(得分:0)
您需要将此文件另存为unicode utf-8格式才能正确使用。