Is there an implementation of org.apache.commons.lang.StringEscapeUtils for .Net?
.net, apache-commons, c#, java
Solution
Using System.Web for HTML there is:
- HttpUtility.HtmlEncode
- HttpUtility.HtmlDecode
For XML escaping you can use the SecurityElement.Escape method in the System.Security namespace. However, there's no equivalent to unescape it that I am aware of. You would have to write your own method that replaces the encoded XML, such as `<` and `&` etc. with their equivalents. The link for the escape method lists the other items.
Problem
I'm porting over a Java project that I wrote which uses the Apache Commons Lang StringEscapeUtils class (particularly the ``` escapeXml unescapeXml escapeHtml unescapeHtml ``` methods). Is there a .Net equivalent? Or perhaps some totally logical bit of C# code that accomplishes the same thing?