Reputation: 338
I want to include a " symbol within a string. So first I just included a double quote like this:
Dim strRequest As String = "<?xml version=""1.0"" encoding=""utf-8"" ?>
But that produced a double quote in the string which I did not expect at all.
<?xml version=""1.0"" encoding=""utf-8"" ?>
So I went so far as to do this:
Dim strRequest As String = "<?xml version="
strRequest &= Chr(34)
strRequest &= "1.0"
But I'm still getting double quotes. Any ideas on why this might be happening?
Upvotes: 0
Views: 63
Reputation: 117029
I've run this code:
Dim strRequest As String = "<?xml version=""1.0"" encoding=""utf-8"" ?>"
Console.WriteLine(strRequest)
I get this result:
<?xml version="1.0" encoding="utf-8" ?>
How do you know you still get the ""
?
I don't know why you don't do this:
Dim xml = <?xml version="1.0" encoding="utf-8" ?>
<root>
<data>Hello, this is some "quoted" text</data>
</root>
That directly gives me a XDocument
object with all of the quotes working fine.
Upvotes: 1
Reputation: 7899
My guess is that Visual Studio makes things a bit confusing for you:
On one hand, in debug mode (when hovering the variable) it is showing you this string: "<?xml version=""1.0"" encoding=""utf-8"" ?>"
.
On the other hand, and what it really holds internally as a value is <?xml version="1.0" encoding="utf-8" ?>
(which is your desired result).
To test it: if instead of just hovering strRequest
you use the Text Visualizer (the magnifying glass icon) you will see the desired result: <?xml version=1.0 encoding=utf-8 ?>
.
Upvotes: 1