removing back slash character from a string

Discussion in 'ASP .Net' started by andrew, Oct 9, 2008.

  1. andrew

    andrew Guest

    I have a weird scenario where I'm trying to use a schema that was loaded into
    an XmlDocument.

    When I try to use that document later (myXDOC.OuterXml)... my text contains
    back slash values in front of every quotation mark and I can't seem to get
    rid of them.

    myXDOC.OuterXml.Replace("\\","") doesn't work.
    myXDOC.OuterXml.Replace(@"\","") doesn't work.
    myXDOC.OuterXml.Replace("\"c,""c) won't compile.
     
    andrew, Oct 9, 2008
    #1
    1. Advertisements

  2. andrew

    K Viltersten Guest

    > myXDOC.OuterXml.Replace("\\","") doesn't work.
    > myXDOC.OuterXml.Replace(@"\","") doesn't work.
    > myXDOC.OuterXml.Replace("\"c,""c) won't compile.


    What do you mean by "doesn't work"? Compile errors?
    Strange functionality? May i be as bold as to suggest
    that you might have assumed that Replace-method is
    of type void (while it's of type string, ennoyingly
    surprising)? Please elaborate.

    --
    Regards
    Konrad Viltersten
    ----------------------------------------
    May all spammers die an agonizing death;
    have no burial places; their souls be
    chased by demons in Gehenna from one room
    to another for all eternity and beyond.
     
    K Viltersten, Oct 9, 2008
    #2
    1. Advertisements

  3. andrew

    Lloyd Sheen Guest

    K Viltersten wrote:
    >> myXDOC.OuterXml.Replace("\\","") doesn't work.
    >> myXDOC.OuterXml.Replace(@"\","") doesn't work.
    >> myXDOC.OuterXml.Replace("\"c,""c) won't compile.

    >
    > What do you mean by "doesn't work"? Compile errors?
    > Strange functionality? May i be as bold as to suggest
    > that you might have assumed that Replace-method is
    > of type void (while it's of type string, ennoyingly
    > surprising)? Please elaborate.
    >

    I didn't see first part of the post but if you are expecting the
    contents of myXDOC to change, that is your problem. You have to assign
    the value of myXDOC.OuterXml.Replace(WHATEVER) to itself. Replace is a
    function and returns a string so your code would most likely look like:

    myXDOC.OuterXml = myXDOC.OuterXml.Replace(WHATEVER)

    LS
     
    Lloyd Sheen, Oct 9, 2008
    #3
  4. andrew

    andrew Guest

    Well I was using those lines within a method call... therefore the method
    would end up with the altered string...

    Ultimately my issue wasn't the backslash characters... the schema that I was
    having trouble with didn't have an XML declaration at the top... as do all
    the rest of our schemas... that's why when streaming out the text the browser
    wasn't displaying anything and it wasn't the back slashes after all.

    "K Viltersten" wrote:

    > > myXDOC.OuterXml.Replace("\\","") doesn't work.
    > > myXDOC.OuterXml.Replace(@"\","") doesn't work.
    > > myXDOC.OuterXml.Replace("\"c,""c) won't compile.

    >
    > What do you mean by "doesn't work"? Compile errors?
    > Strange functionality? May i be as bold as to suggest
    > that you might have assumed that Replace-method is
    > of type void (while it's of type string, ennoyingly
    > surprising)? Please elaborate.
    >
    > --
    > Regards
    > Konrad Viltersten
    > ----------------------------------------
    > May all spammers die an agonizing death;
    > have no burial places; their souls be
    > chased by demons in Gehenna from one room
    > to another for all eternity and beyond.
    >
    >
    >
     
    andrew, Oct 9, 2008
    #4
  5. andrew

    Hillbilly Guest

    As it turns out this blogged trailing slash topic [1] was found just this
    week

    [1]
    http://blogs.msdn.com/gerryo/archive/2008/07/24/mcad-new-paths-to-certification.aspx


    "andrew" <> wrote in message
    news:...
    >I have a weird scenario where I'm trying to use a schema that was loaded
    >into
    > an XmlDocument.
    >
    > When I try to use that document later (myXDOC.OuterXml)... my text
    > contains
    > back slash values in front of every quotation mark and I can't seem to get
    > rid of them.
    >
    > myXDOC.OuterXml.Replace("\\","") doesn't work.
    > myXDOC.OuterXml.Replace(@"\","") doesn't work.
    > myXDOC.OuterXml.Replace("\"c,""c) won't compile.
     
    Hillbilly, Oct 9, 2008
    #5
  6. andrew

    Jeff Dillon Guest

    Jeff Dillon, Oct 9, 2008
    #6
  7. andrew

    K Viltersten Guest

    >>> myXDOC.OuterXml.Replace("\\","") doesn't work.
    >>> myXDOC.OuterXml.Replace(@"\","") doesn't work.
    >>> myXDOC.OuterXml.Replace("\"c,""c) won't compile.

    >>
    >> What do you mean by "doesn't work"? Compile errors?
    >> Strange functionality? May i be as bold as to suggest
    >> that you might have assumed that Replace-method is
    >> of type void (while it's of type string, ennoyingly
    >> surprising)? Please elaborate.
    >>

    > I didn't see first part of the post but if you are expecting the contents
    > of myXDOC to change, that is your problem.


    I don't expect that. However, i forget this, every
    now and then.

    > You have to assign the value...


    Yes, that's the point of what i wrote. Perhaps not
    clear enough. The method is not a void, but string
    type. Hence, one needs to catch the result of it.

    --
    Regards
    Konrad Viltersten
    ----------------------------------------
    May all spammers die an agonizing death;
    have no burial places; their souls be
    chased by demons in Gehenna from one room
    to another for all eternity and beyond.
     
    K Viltersten, Oct 9, 2008
    #7
  8. andrew

    Hillbilly Guest

    Hillbilly, Oct 9, 2008
    #8
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bruce
    Replies:
    6
    Views:
    1,079
    Simon Forman
    Jul 4, 2006
  2. bruce
    Replies:
    1
    Views:
    752
    Marc 'BlackJack' Rintsch
    Jul 4, 2006
  3. bruce
    Replies:
    2
    Views:
    842
    Fredrik Lundh
    Jul 4, 2006
  4. bruce
    Replies:
    1
    Views:
    2,827
    Steven D'Aprano
    Jul 4, 2006
  5. Brand Bogard

    8 bit character string to 16 bit character string

    Brand Bogard, May 25, 2006, in forum: C Programming
    Replies:
    8
    Views:
    1,000
    those who know me have no need of my name
    May 28, 2006
  6. Replies:
    0
    Views:
    2,256
  7. Replies:
    4
    Views:
    221
    Evertjan.
    Jun 26, 2004
  8. Bart Vandewoestyne
    Replies:
    8
    Views:
    1,123
    Bart Vandewoestyne
    Sep 25, 2012
Loading...