I have a local file path containing “\” and I need to change all occurrences to “/” for a remote file path.
I have tried
myString.replace("\","/")
and
myString.replace(Convert.ToChar(92), Convert.ToChar(47))
Both seem to leave the “\” in tact..
Answer:
NewString = myString.replace("\","/")
The problem was that I was not assigning it to a variable. Escaping the slash actually made it fail, in vb.net at least.
Strings are immutable. The
Replacemethod returns a new string rather than affecting the current string, therefore you need to capture the result in a variable. If you’re using VB.NET there’s no need to escape the backslash, however in C# it must be escaped by using 2 of them.VB.NET (no escaping needed):
C# (backslash escaped):
I assume you’re using VB.NET since you don’t include a semicolon, didn’t escape the backslash and due to the casing of the replace method used.