문제

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