Thanks to NgM I am using StringBuilder in .NET 3.5 to find and escape special chars. However, when I use the ToString method, it escapes the escape chars which then makes the previous exercise useless. Anyone know how to get around that?
Here is the code:
private String ParseAndEscapeSpecialChars(String input)
{
StringBuilder sBuilder = new StringBuilder(input);
String output;
String specialChars = @"([-\]\[<>\?\*\\\""/\|\~\(\)\#/=><+\%&\^\'])";
Regex expression = new Regex(specialChars);
if (expression.IsMatch(input))
{
sBuilder.Replace(@"\", @"\\");
sBuilder.Replace(@"'", @"\'");
}
output = sBuilder.ToString();
return output;
}
Here are the results from debug:
input "005 - SomeCompany's/OtherCompany's Support Center"
sBuilder {005 - SomeCompany\'s/OtherCompany\'s Support Center}
output "005 - SomeCompany\\'s/OtherCompany\\'s Support Center"
StringBuilder
doesn't escape characters. It does nothing special or clever. Dollars to doughnuts you're just seeing this in the debugger, which does show you an escaped version.
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