For .net 4.0 + there is standard
HttpUtility.JavaScriptStringEncode
For earlier west wind solution described by Lone Coder is quite nice
More Related Contents:
- Can I escape a double quote in a verbatim string literal?
- Can I convert a C# string value to an escaped string literal?
- Unrecognized escape sequence for path string containing backslashes
- Escape Special Character in Regex
- Escape invalid XML characters in C#
- String escape into XML
- How to escape JSON string?
- Escape text for HTML
- How do I write the escape char ‘\’ to code
- @(at) sign in file path/string [duplicate]
- Convert XmlDocument to String
- Finding quoted strings with escaped quotes in C# using a regular expression
- How can I Unescape and Reescape strings in .net?
- C# – What does “\0” equate to?
- two different DLL with same namespace
- How can a Word document be created in C#? [closed]
- How to detect if a property exists on an ExpandoObject?
- Not able to cast string to int. Error msg: Input string was not in a correct format
- Observable Stack and Queue
- Having the output of a console application in Visual Studio instead of the console
- ASP.NET MVC Routing – add .html extension to routes
- Microsoft Visual Studio and C#: How to Visually Add Events to Controls?
- What does new() mean?
- Global setting for AsNoTracking()?
- Auto-Implemented Properties c#
- Extract only right most n letters from a string
- C# Get property value without creating instance?
- EF models. Navigation properties can only participate in a single relationship
- How to merge two lists using LINQ?
- Detect if non DPI-aware application has been scaled/virtualized