Pergunta

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 "\\"?

Foi útil?

Solução

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.

Outras dicas

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"
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top