I want to replace "\" with empty string. I have tried many things but doesn't work.
MyText like this test/test\test:test*test?test"test<test>test|test
MyText.Replace("\\\"", "").Replace("\\", "").Replace("\"", "").Replace("\\", "");
How to do this in correctly?
It should be as simple as the following:
string oldStr = "test/test\\test:test*test?test\"test<test>test|test";
string newStr = oldStr.Replace(@"\", string.Empty);
Note that I've used the @ sign to treat the strings as verbatim string literals. This avoids the need to escape the backslash each time it is used.
EDIT Note also that the Replace function does not replace the contents of the string you call it on. Instead, it returns a new string with the replacement made. I suspect this is the actual cause of your issue, judging by the code you posted.
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