how to automatically escape the path

耗尽温柔 提交于 2019-12-01 17:47:53

问题


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


回答1:


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



回答2:


Try this:

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



回答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.




回答4:


You can always try something like: System.Text.RegularExpressions.Regex.Unescape, of course that will do all escaped characters.



来源:https://stackoverflow.com/questions/4543686/how-to-automatically-escape-the-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!