removing back slash character from a string

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

K Viltersten

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

Lloyd Sheen

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
 
A

andrew

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

K Viltersten

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.
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top