0

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

Martin Liversage
  • 104,481
  • 22
  • 209
  • 256

2 Answers2

1

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.

Jodrell
  • 34,946
  • 5
  • 87
  • 124
0

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"
weston
  • 54,145
  • 21
  • 145
  • 203
Paolo
  • 22,188
  • 6
  • 42
  • 49