ASP.NET实现纯文本转HTML ,可以实现的功能:输入:"ab\r\ncde\r\nfghi"输出:"<p>ab</p><p>cde</p><p>fghi</p>",注意无论任何输出<p>和</p>都要配对出现,且<p>和</p>之间不能为空
public static string Text2HtmlSimple( string input) |
03 |
StringBuilder sb = new StringBuilder(); |
08 |
string toAppend = string .Empty; |
09 |
int pos = input.IndexOf( "\r\n" , index); |
14 |
else if (pos == input.Length - 2) |
16 |
toAppend = input.Substring(index, pos - index); |
17 |
if (! string .IsNullOrEmpty(toAppend)) |
19 |
sb.AppendFormat( "{0}</p>" , toAppend); |
25 |
toAppend = input.Substring(index, pos - index); |
26 |
if (! string .IsNullOrEmpty(toAppend)) |
28 |
sb.AppendFormat( "{0}</p><p>" , toAppend); |
34 |
toAppend = input.Substring(index, input.Length - index); |
35 |
sb.AppendFormat( "{0}</p>" , toAppend); |
39 |
while (index < input.Length); |
(责任编辑:admin) |