vinay teja reddy
vinay teja reddy

Reputation: 259

How to replace forward slash with backward slash

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

Upvotes: 19

Views: 55346

Answers (2)

Sayse
Sayse

Reputation: 43300

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

Upvotes: 48

Optimus Prime
Optimus Prime

Reputation: 6907

Try escaping backslash,

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

Upvotes: 8

Related Questions