removing escape character from a C# string

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.
 
P

Pete

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:
 
P

Pete

sorry..

This works:

string x = "\"water lillies\"";

string x = x.Replace("\"","");
 
J

Jon Skeet [C# MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top