0

I have a string ,it gives a source path from a png image ex:

C:\pictures\picture1.png

But I will replace the '\' character to '\ \' (two \ character )with this line :

my data is C:\pictures\picture1.png

 public string rep(string data) 
        {
            data.Replace('\','\\');
            return data;
        }

when I rite data.Replace('\','\') the next characters after '\' comes to description line what can I do I must use the file source so :

C:\\pictures\\picture1.png
tshepang
  • 12,111
  • 21
  • 91
  • 136
Ebrar Bayburt
  • 37
  • 1
  • 3
  • 9

2 Answers2

3

You need this:

data = data.Replace("\\", "\\\\");

Backslashes must be doubled in strings.

(Or use "raw strings":

data = data.Replace(@"\", @"\\");

}

RichieHindle
  • 272,464
  • 47
  • 358
  • 399
2

Your:

data.Replace("\","\\\\");

Line is not doing anything since Replace returns a new string with the result. Perhaps what you intend to do is data=data.Replace()...?

Icarus
  • 63,293
  • 14
  • 100
  • 115