removing escape character from a C# string

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello everyone,



I am trying to remove the escape characters from my C# string. This is the
string "\"Water lilies.jpg\"". I want to just get "Water lilies.jpg". I
tried indexof, that didn't work.

string x = "\"Water lilies.jpg\""

int y = x.Indexof("\\",0)



y returned -1

I cannot use substring because the name can change. It can be water Lillies
or something else or lengthier name.
 
Vinki said:
Hello everyone,



I am trying to remove the escape characters from my C# string. This is
the
string "\"Water lilies.jpg\"". I want to just get "Water lilies.jpg". I
tried indexof, that didn't work.

string x = "\"Water lilies.jpg\""


This works for me:
 
Vinki said:
I am trying to remove the escape characters from my C# string. This is the
string "\"Water lilies.jpg\"". I want to just get "Water lilies.jpg".

And that *is* what you've got. I believe the problem is that you're
looking at the string in the debugger, which is escaping the string for
you. Try printing it out (eg with Console.WriteLine) to see the actual
value.
 
Back
Top