0

I am doing this, like in this answer :

string test = "test\"test";
test = test.Replace("\\\"", "");

but the result is still test = "test\"test".

The result shoud be test = "testtest", Why my replace does not work ?

Mehdi Souregi
  • 3,153
  • 5
  • 36
  • 53

1 Answers1

7

Because your string is actually test"test not test\"test. The backslash is used to escape double quote, it's not in the actual string.

Try using a verbatim string:

string test = @"test\""test"; // equivalent to test\\\"test
Selman Genç
  • 100,147
  • 13
  • 119
  • 184
  • The verbatim string doesn't really add much. You have to escape one of the characters either way. Without the verbatim string, it becomes `"test\\"test"`. Regardless, you have the right of the issue - escaped string was escaped :) – CodeHxr Oct 04 '18 at 14:53