简体   繁体   中英

How to decode encoded string for javascript

This is encoded HTML code to be used at javascript function

<div class=\"ProductDetail\"><div style=\"width:780px\">\r\n\t<div class=\"baslik\" style=\"margin: 0px; padding: 5px 10px; border-width: 5px 0px 1px; border-top-style: solid; border-bottom-style: solid; border-top-color: rgb(255, 255, 255); border-bottom-color: rgb(153, 165, 165); vertical-align: baseline; color: rgb(0, 0, 0); clear: both; line-height: 14px; font-family: 'Lucida Grande', sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(219, 223, 226);\">    Di\u011fer \u00d6zellikler<\/div><\/div><\/div>

When decoded properly it becomes below

<div class="ProductDetail"><div style="width:780px">
<div class="baslik" style="margin: 0px; padding: 5px 10px; border-width: 5px 0px 1px; border-top-style: solid; border-bottom-style: solid; border-top-color: rgb(255, 255, 255); border-bottom-color: rgb(153, 165, 165); vertical-align: baseline; color: rgb(0, 0, 0); clear: both; line-height: 14px; font-family: 'Lucida Grande', sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(219, 223, 226);">    Diğer Özellikler</div></div></div>

This website has both decode and encode features

http://www.freeformatter.com/javascript-escape.html#ad-output

I could find HttpUtility.JavaScriptStringEncode at c# however i couldn't find any function class etc to decode encoded string

So i need help about how to decode like that website does

.net 4.5 c#

Wow answer was so easy i just found out

and yet many experienced developers here voted my previous thread to close :D

Single line and works perfect

Regex.Unescape(string);

Did you try:

        var unescapedString = Microsoft.JScript.GlobalObject.unescape(yourEscapedString);
        var escapedString = Microsoft.JScript.GlobalObject.escape(yourUnescapedString);

You should add Microsoft.JScript reference to your project.

The encoding shown is sufficient to make a JavaScript literal. This won't need any additional decoding as the interpreter will do it for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM