C# alternative for javascript escape function
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: 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. 回答1: You can use: string encoded = HttpUtility . JavaScriptStringEncode ( str ); Note: You need at least ASP.NET 4.0 to run the above code. 回答2: The best solution I've seen is mentioned on this blog - C#: Equivalent of JavaScript escape function by Kaushik