有沒有解碼用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