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

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

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

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. AviraM
    Replies:
    2
    Views:
    6,330
    Manish Pandit
    Sep 28, 2006
  2. destroooooy
    Replies:
    4
    Views:
    644
    Arnaud Delobelle
    Apr 29, 2008
  3. Chris Rebert

    Re: string replace for back slash

    Chris Rebert, Feb 5, 2009, in forum: Python
    Replies:
    0
    Views:
    410
    Chris Rebert
    Feb 5, 2009
  4. Replies:
    0
    Views:
    2,004
  5. Replies:
    4
    Views:
    142
    Evertjan.
    Jun 26, 2004
Loading...

Share This Page