admin管理员组文章数量:1192919
I am trying to analyse some JavaScript
, and one line is
var x = unescape("%u4141%u4141 ......");
with lots of characters in form %uxxxx
.
I want to rewrite the JavaScript
in c#
but can't figure out the proper function to decode a string of characters like this. I've tried
HttpUtility.HTMLDecode("%u4141%u4141");
but this did not change these characters at all.
How can I accomplish this in c#?
I am trying to analyse some JavaScript
, and one line is
var x = unescape("%u4141%u4141 ......");
with lots of characters in form %uxxxx
.
I want to rewrite the JavaScript
in c#
but can't figure out the proper function to decode a string of characters like this. I've tried
HttpUtility.HTMLDecode("%u4141%u4141");
but this did not change these characters at all.
How can I accomplish this in c#?
Share Improve this question edited May 8, 2015 at 6:03 gotqn 43.6k46 gold badges165 silver badges254 bronze badges asked Jul 26, 2011 at 17:09 vivek a.vivek a. 991 gold badge1 silver badge3 bronze badges 1- 1 You are mixing up two different escaping/unescaping methods: one is for entities inside a HTML file, the other is for URLs, i.e. addresses. – Philip Daubmeier Commented Jun 30, 2012 at 14:55
6 Answers
Reset to default 14You can use UrlDecode:
string decoded = HttpUtility.UrlDecode("%u4141%u4141");
decoded
would then contain "䅁䅁"
.
As other have pointed out, changing the %
to \
would work, but UrlDecode
is the preferred method, since that ensures that other escaped symbols are translated correctly as well.
You need HttpUtility.UrlDecode
. You shouldn't really be using escape/unescape
in most cases nowadays, you should be using things like encodeURI/decodeURI/encodeURIComponent
.
When are you supposed to use escape instead of encodeURI / encodeURIComponent?
This question covers the issue of why escape/unescape
are a bad idea.
You can call bellow method to achieve the same effect as Javascript escape/unescape method
Microsoft.JScript.GlobalObject.unescape();
Microsoft.JScript.GlobalObject.escape();
Change the % signs to backslashes and you have a C# string literal. C# treats \uxxxx as an escape sequence, with xxxx being 4 digits.
In basic string usage you can initiate string variable in Unicode: var someLine="\u4141"; If it is possible - replace all "%u" with "\u".
edit the web.config the following parameter:
< globalization requestEncoding="iso-8859-15" responseEncoding="utf-8" >responseHeaderEncoding="utf-8"
in < system.web >
本文标签: what is the c equivalent to javascript39s unescape()Stack Overflow
版权声明:本文标题:what is the c# equivalent to javascript's unescape()? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738474735a2088796.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论