Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to automatically escape the path

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

like image 296
user496949 Avatar asked Dec 28 '10 04:12

user496949


People also ask

How do I escape the path of a file?

Three Ways to Escape Spaces on WindowsBy enclosing the path (or parts of it) in double quotation marks ( ” ). By adding a caret character ( ^ ) before each space. (This only works in Command Prompt/CMD, and it doesn't seem to work with every command.) By adding a grave accent character ( ` ) before each space.

How do you escape a path in Java?

A character with a backslash (\) just before it is an escape sequence or escape character.

How do I escape a character in R?

However, note that R will add a "\n" at the end of each line break. This is called an escape character, and the n character indicates a new line.


2 Answers

Try this:

string path = @"c:\user\test\test.jpg";
like image 65
Abe Miessler Avatar answered Oct 12 '22 13:10

Abe Miessler


string s = s.Replace(@"\", @"\\");
like image 37
Ross Avatar answered Oct 12 '22 13:10

Ross