how to automatically escape the path

20,800

Solution 1

string s = s.Replace(@"\", @"\\");

Solution 2

Try this:

string path = @"c:\user\test\test.jpg";

Solution 3

you would only require escaping if you are using string literal in the code. why would you require automatic escaping anyways. you can use @ before the literal that requires no escaping.

Share:
20,800
user496949
Author by

user496949

Updated on July 15, 2022

Comments

  • user496949
    user496949 almost 2 years

    I have a path string like c:\user\test\test.jpg, how can I make it c:\\user\\test\\test.jpg?

  • Admin
    Admin about 9 years
    how to do opposite of this? and when there are random no of \\ in the path for e.g. how can i make this path C:\\abcdef\\\\smstr\\iretrieval\\20_newsgroups\\20_newsgroup‌​s\\alt.atheism\\ as C:\abcdef\smstr\iretrieval\20_newsgroups\20_newsgroups\alt.a‌​theism\?