Minor bug in plain-text to HTML conversion using Regular Expressions
I am facing a minor bug when doing the conversion from plain text to HTML. What might be the reason for this?
Input: (plain-text)
this is test input.
Output: (virtual plain-text but HTML)
this is test 开发者_高级运维input.
BUG: Moves one or two spaces forward. I have no clue why is this happening.
Code for your reference
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>");
I tested the following, and it works (eg. no spaces at beginning of output):
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");
I would investigate the class used to instantiate mailItem
, and review at the HTMLBody
property to see if anything funny is happening there.
精彩评论