I'm doing a C# project for school.

I need to extract a .zip file but i have a problem.

I get the path where the file that is going to be extract is with FolderBrowserDialog and everything is ok, but the FolderBrowserDialog gives me something like "C:\Users\Zé Eduardo\Music" , but i need something like this "C:\\Users\\Zé Eduardo\\Music".

How can i transform "\" to "\\"?

有帮助吗?

解决方案

well, this is the answer to your question but you are probably asking the wrong question,

var transformedString = badString.Replace(@"\", @"\\");

The @ in the literal means, this is a verbatim string so normal escaping rules don't apply. Effectively, you don't need to escape the escape character.

其他提示

Something simple would be to use string replace:

String original = @"c:\some\path";
String @fixed = original.Replace("\\", "\\\\"); //Note the double escaping!

//fixed contains "c:\\some\\path"
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top