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
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.
In java, use this: str = str. replace("\\", "/");
replace('\\', '/') works just fine.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With