有没有解码用C#中的HttpUtility.JavaScriptStringEncode()编码的字符串的方法?如何解码用JavaScriptStringEncoded编码的字符串?
上述编码字符串:
<div class=\"header\"><h2>\u00FC<\/h2><script>\n<\/script>\n
我的临时解决办法是:
public static string JavaScriptStringDecode(string source)
{
// Replace some chars.
var decoded = source.Replace(@"\'", "'")
.Replace(@"\""", @"""")
.Replace(@"\/", "/")
.Replace(@"\t", "\t")
.Replace(@"\n", "\n");
// Replace unicode escaped text.
var rx = new Regex(@"\\[uU]([0-9A-F]{4})");
decoded = rx.Replace(decoded, match => ((char)Int32.Parse(match.Value.Substring(2), NumberStyles.HexNumber))
.ToString(CultureInfo.InvariantCulture));
return decoded;
}
预期用途是web内容解析器。我不拥有这些内容。 – 2013-02-20 15:42:57
没有预期的用途?你在开玩笑吧? – misteraidan 2013-07-30 05:56:31