escapedItem = itemToEscape.Replace("&", "&")
.Replace("<", "<")
.Replace(">", ">")
.Replace("'", "'")
.Replace("\"", """);
Though this technically works, there is an easier way built right in to the .Net framework. If we reference System.Security we can replace the above code with
escapedItem = SecurityElement.Escape(itemToEscape);
In both cases, the string
If (x < 2) & (y > 3), where \"x\" isn't...
is replaced with
If (x < 2) & (y > 3), where "x" isn't...
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.