removing escape character from a C# string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?Vmlua2k=?=

    removing escape character from a C# string

    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.

  • Pete

    #2
    Re: removing escape character from a C# string


    "Vinki" <Vinki@discussi ons.microsoft.c omwrote in message
    news:6FCF87C9-F8E4-4F5B-98DD-7A3423A3793D@mi crosoft.com...
    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:


    Comment

    • Pete

      #3
      Re: removing escape character from a C# string


      "Pete" <me@ineedhelp.o rgwrote in message
      news:vB0Ih.2294 50$ff2.162059@f e02.news.easyne ws.com...
      >
      "Vinki" <Vinki@discussi ons.microsoft.c omwrote in message
      news:6FCF87C9-F8E4-4F5B-98DD-7A3423A3793D@mi crosoft.com...
      >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\""
      >
      >
      sorry..

      This works:

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

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



      Comment

      • =?Utf-8?B?Vmlua2k=?=

        #4
        Re: removing escape character from a C# string

        Thanks Pete.

        "Pete" wrote:
        >
        "Pete" <me@ineedhelp.o rgwrote in message
        news:vB0Ih.2294 50$ff2.162059@f e02.news.easyne ws.com...

        "Vinki" <Vinki@discussi ons.microsoft.c omwrote in message
        news:6FCF87C9-F8E4-4F5B-98DD-7A3423A3793D@mi crosoft.com...
        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\""
        sorry..
        >
        This works:
        >
        string x = "\"water lillies\"";
        >
        string x = x.Replace("\"", "");
        >
        >
        >
        >

        Comment

        • Jon Skeet [C# MVP]

          #5
          Re: removing escape character from a C# string

          Vinki <Vinki@discussi ons.microsoft.c omwrote:
          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.WriteLi ne) to see the actual
          value.

          --
          Jon Skeet - <skeet@pobox.co m>
          http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
          If replying to the group, please do not mail me too

          Comment

          Working...