What is the best way to replace all occurrences of "" with "/" in a string in c#?
I've tried the following options but neither work.
- variable.Replace("", "/");
- variable.Replace(@"", @"/");
What is the best way to replace all occurrences of "" with "/" in a string in c#?
I've tried the following options but neither work.
You should assign result of replacement:
var res = variable. Replace("\\", "/"); // you need "\\" because "\" is escape symbol.
or
var res = variable.Replace(@"\", "/");
As @UweKeim says in a comment, you have to store the result of the Replace
call. Like this:
variable = variable.Replace("@"\", @"/");
var newVar = variable.Replace("\\", "/");