在从纯文本到HTML的转换过程中,我面临一个小错误。这可能是什么原因?
输入:(纯文本)
this is test input.输出:(虚拟纯文本但HTML)
this is test input.BUG:向前移动一个或两个空格。我不知道为什么会这样。
代码用于您的参考
string Text = "<html><body><pre style=\"font-family:consolas;font-size:88%;\">"
+ mailItem.Body + "</pre></body></html>";
mailItem.HTMLBody = Text;
mailItem.HTMLBody = Regex.Replace(mailItem.HTMLBody,
"(ASA[a-z][a-z][0-9][0-9])", "<a href=\"http://stack.com/eg=$&\">$&</a>");发布于 2011-07-06 16:26:12
我测试了下面的内容,结果成功了。在输出开始时没有空格):
string mailItemBody = "ASAss87";
string oldText = "<html><body><pre style=\"font-family:consolas;font-size:88%;\">"
+ mailItemBody + "</pre></body></html>";
string newText = Regex.Replace(
oldText, "(ASA[a-z][a-z][0-9][0-9])", "<a href=\"http://stack.com/eg=$&\">$&</a>");
Console.WriteLine("Old text is: \n\n" + oldText + "\n\n");
Console.WriteLine("New text is: \n\n" + newText + "\n\n");我将研究用于实例化mailItem的类,并检查HTMLBody属性以查看那里是否发生了什么有趣的事情。
https://stackoverflow.com/questions/6597964
复制相似问题