Replace slashes in .Net

I have a local file path containing "\" and I need to change all occurrences to "/" for the remote file path.

I tried

myString.replace("\","/")

and

myString.replace(Convert.ToChar(92), Convert.ToChar(47)) 

Both seem to leave a \ in time.

Answer:

NewString = myString.replace("\","/")

The problem was that I did not assign it to a variable. Avoiding a slash actually made her fail, at least in vb.net.

+3
source share
4 answers

Lines are immutable. The method Replacereturns a new line, and does not affect the current line, so you need to commit the result to a variable. If you use VB.NET you don't need to hide the backslash, however in C # it needs to be escaped using 2 of them.

VB.NET( ):

myString = myString.Replace("\","/")

# ( ):

myString = myString.Replace("\\","/");

, VB.NET, , - .

+10

\ , \ @. , myString.replace myString ( , .. ), , .

string myNewString = myString.replace("\\","/")

string myNewString = mmyString.replace(@"\","/")

string myNewString = mmyString.replace('\\','/')
+4

\:

myString.replace("\\","/")

(#):

myString.replace(@"\","/")

, char s:

myString.replace('\','/')
0
source

You need to exit back slash (\)using extra back slash (\\) , try the following:

myString.replace("\\","/")
0
source

Source: https://habr.com/ru/post/1734779/


All Articles