In my code I want to replace backslash character \
by a forward slash character /
in a string. I've tried the following code:
string str = chosen_file.Replace("/", @"\");
where, chosen_file
is a string
which contains numerous occurances of the \
character.
But it doesn't seem to be working.
Can I know any other solutions for this issue?
If you look at the definition of String.Replace:
public string Replace(
string oldValue,
string newValue
)
and your call:
chosen_file.Replace("/", @"\");
You are replacing forward slashses with backslashes. If you swap the arguments you should be getting the desired behavior.
Double slash will show only at the time of debugging.If you print this value in console application or lable box then you can see the correct answer.