如何在字符串中插入html

问题描述:

我想知道是否可以使用C#将HTML插入字符串中.

I am wondering if it is possible to have HTML be inserted into a string using C#.

作为将创建的HtmlTable设置为字符串的方法的示例.

as example a method that sets a created HtmlTable into a string.

public class HTMLTableToString
    {
        public static String Convert(Table table)
        {
            StringWriter stringWriter = new StringWriter();
            using (HtmlTextWriter writer = new HtmlTextWriter(stringWriter))
            {
                table.RenderControl(writer);
            }
            return stringWriter.ToString();
        }
    }


是的.
string s = "<a href=\"http://www.codeproject.com/Questions/342157/how-to-insert-html-in-a-string\">how to insert html in a string</a>[<a href=\"http://www.codeproject.com/Questions/342157/how-to-insert-html-in-a-string\" target=\"_blank\" title=\"New Window\">^</a>]";