removing back slash character from a string

  • Thread starter Thread starter andrew
  • Start date Start date
A

andrew

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.
 
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.
 
K said:
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
 
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.
 
myXDOC.OuterXml.Replace("\\","") doesn't work.
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.
 
Back
Top