开发者

Web browser control display plain text mail

I have a c# app which is supposed to display 开发者_开发百科email. the email may be HTML or plain text but i am using web browser control in both cases. the problem is web browser control is ignoring all the escape characters of plain text and the mail appear as a single line.

the work around i am using is to replace escape character "\n" or "\r" to <br>. is there any other good way to do this.

thanks in advance.


You can surround the text with <pre> and </pre> (stands for "preformatted") tag. See here: HTML pre Tag


I think, the only way is the replacing "\r\n" for <br/>. Use the StringBuilder class for it.

var htmlText = new StringBuilder(text);
htmlText.Replace("\r\n", "\n")
        .Replace("\r", "\n")
        .Replace("\n", "<br/>");
webBrowser.DocumentText = htmlText.ToString();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜