Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace forward slash with backward slash

Tags:

string

c#

.net

i have a string /Images/Me.jpg i want to replace forward slashes with backward slashes like this \Images\Me.jpg, iam using string.Replace("/","\"); but the output is \\Images\\Me.jpg please help

like image 374
vinay teja reddy Avatar asked Aug 16 '13 17:08

vinay teja reddy


People also ask

How do you change forward slash to backward slash?

Press \/ to change every backslash to a forward slash, in the current line. Press \\ to change every forward slash to a backslash, in the current line.

How do you change backward slash to forward slash in Java?

In java, use this: str = str. replace("\\", "/");

How do you change the backslash with a forward slash in Python?

replace('\\', '/') works just fine.

How do you remove a forward slash from a string?

To replace all forward slashes in a string: Call the replace() method, passing it a regular expression that matches all forward slashes as the first parameter and the replacement string as the second. The replace method will return a new string with all forward slashes replaced.


1 Answers

you need to escape the slashes

string.Replace("/", "\\")
string.Replace("/", @"\")

Visual studios intellisense will still show "\\", if you hover over the string, you will find a magnifying glass, click it. This will show the real string

like image 164
Sayse Avatar answered Sep 29 '22 11:09

Sayse