如何转换此字符串
<img alt="" src="http://win-thgn9fd7gfo:37996/Style Library/UWW/images/logo01.gif" style="BORDER: 0px solid; ">
到
<img alt="" src="http://win-thgn9fd7gfo:37996/Style Library/UWW/images/logo01.gif" style="BORDER: 0px solid;">
答案 0 :(得分:4)
使用HttpUtility.HtmlDecode进行此类操作......
答案 1 :(得分:3)
见MSDN article on HtmlDecode。您可以使用System.Web.HttpUtility.HtmlDecode()
将这些转换为原始的HTML等效字符。
var html = "<img alt=\"\" src=\"http://win-thgn9fd7gfo:37996/Style Library/UWW/images/logo01.gif\" style=\"BORDER: 0px solid; \">";
html = HttpUtility.HtmlEncode(html);
// html now = "<img alt="" src="http://win-thgn9fd7gfo:37996/Style Library/UWW/images/logo01.gif" style="BORDER: 0px solid; ">"
var html = HttpUtility.HtmlDecode(html);
// html is now back to its original value.
答案 2 :(得分:0)
myEncodedString = HttpUtility.HtmlEncode(myString);
被盗:http://msdn.microsoft.com/en-us/library/aa332854%28v=vs.71%29.aspx
[C#]
using System;
using System.Web;
using System.IO;
class MyNewClass
{
public static void Main()
{
String myString;
Console.WriteLine("Enter a string having '&' or '\"' in it: ");
myString=Console.ReadLine();
String myEncodedString;
// Encode the string.
myEncodedString = HttpUtility.HtmlEncode(myString);
Console.WriteLine("HTML Encoded string is "+myEncodedString);
StringWriter myWriter = new StringWriter();
// Decode the encoded string.
HttpUtility.HtmlDecode(myEncodedString, myWriter);
Console.Write("Decoded string of the above encoded string is "+
myWriter.ToString());
}
}