In C# you handle a special character in a string by escaping it with a backslash, e.g. adding a carriage return and line feed using "\r\n". Because a string literal is delimited by double quotes, a double quote is considered a special character so you escape it the same way, e.g. "He said \"Hello\" to me". A char literal is delimited by single quotes though, so a double quote is not a special character in that case. As such, a double quote char literal is simply '"'.
Because an empty string is a string and not a char, you must use the overload of string.Replace that replaces a string with a string rather than the one that replaces a char with a char. As such, you need a string that contains a double quote. Based on my first paragraph, that gives you two choices:
// Using a string literal with an escape character.
str1 = str1.Replace("\"", string.Empty);
// Using a char literal.
str2 = str2.Replace('"'.ToString(), string.Empty);
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.