what is an alternative for javascript escape function in c# for e.g suppose a string:"Hi Foster's i'm missing /you" will give "Hi%20Foster%27s%20i%27m%20missing%20/you" if we use javascript escape function, but what is the alternative for c#. i have searched for it but no use.
You can use:
string encoded = HttpUtility.JavaScriptStringEncode(str);
Note: You need at least ASP.NET 4.0 to run the above code.
var unescapedString = Microsoft.JScript.GlobalObject.unescape(yourEscapedString);
var escapedString = Microsoft.JScript.GlobalObject.escape(yourUnescapedString);
The best solution I've seen is mentioned on this blog - C#: Equivalent of JavaScript escape function by Kaushik Chakraborti. There is more to escaping javascript than simply url-encoding or replacing spaces with entities.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With