-2

i need to replace " with "" in full xml string.

i have this:

Dim mioxml As String = "< xml version = "1.0" encoding="UTF-8"> < orderid > Range < /orderid>< operation >RangeA2< /operation>< /order>"

mioxml = mioxml.Replace(""","""")

But on the firt line i have an error (Expected end of instruction)

So i think the problem is on the Dim of mioxml.

Thank you

Julian
  • 33,915
  • 22
  • 119
  • 174
riccio99
  • 11
  • 4

2 Answers2

0

You are able to use XML literals in Visual Studios, take a look at the following example:

Dim mioxml As XDocument = New XDocument(
                              New XDeclaration("1.0", "utf-8", "yes"), 
                              <order>
                                <orderid>Range</orderid>
                                <operation>RangeA2</operation>
                              </order>)
Console.WriteLine(mioxml.ToString())

This allows you to write XML elements without having to worry about escaping the double-quotes.

David
  • 5,877
  • 3
  • 23
  • 40
  • I cannot change the string. The string it is like i have. I have only to change the double quote with double double quote without changing the string. i have a lot of that string. – riccio99 Jun 23 '19 at 20:35
  • @riccio99 Then you will need to escape the double quote. In VB.NET that is done by having two sequential double quotes. E.g. `Dim foo As String = "Hello ""world"" this is escaped."` – David Jun 24 '19 at 03:22
0

Thank you David, this is what I have done as per your suggestion.

Dim mioxml As XDocument =
<?xml version="1.0" encoding="UTF-8"?>
<orders xmlns:xsi="http//www.w3.org/2001/XMLSchema-instance">
    <order>
      <orderid>Range</orderid>
      <operation>RangeA2</operation>
    </order>
</orders>

Dim mioxml2 = mioxml.ToString
mioxml2 = mioxml2.Replace("""", """""")
MsgBox(mioxml2.ToString)
Paul Farry
  • 4,730
  • 2
  • 35
  • 61
riccio99
  • 11
  • 4