Question Weird problem with strings

MacAttack

New member
Joined
Dec 20, 2009
Messages
1
Programming Experience
1-3
I am reading an XML file the input looks like this

VB.NET:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> 
- <Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">
  <Template>Normal.dotm</Template> 
  <TotalTime>42</TotalTime> 
  <Pages>2</Pages> 
  <Words>341</Words>

I am importing it into a string using this code
VB.NET:
        OFDone.ShowDialog()
        Dim sr As New System.IO.StreamReader(OFDone.FileName)
        path = OFDone.FileName
        sr.Close()
        TXTpath.Text = path
        Dim fs As FileStream = File.Open(path, FileMode.Open, FileAccess.Read)
        Dim buffer(fs.Length) As Byte
        fs.Read(buffer, 0, fs.Length - 1)
        input = System.Text.UTF8Encoding.UTF8.GetString(buffer)

When I run this piece of code trying to get everything between the template tags and the total time tags.

VB.NET:
 Private Sub app()
        Dim x As Integer
        x = input.IndexOf("<Template")
        y = input.IndexOf("</Template")
        Info.template = input.Substring(x + 10, y)
        x = input.IndexOf("<TotalTime>")
        y = input.IndexOf("</TotalTime>")
        Info.totaltime = input.Substring(x + 10, y)

    End Sub

the tags are the only ones in the file. When I run this the output i get is

Template gives me this
VB.NET:
Normal.dotm</Template><TotalTime>42</TotalTime><Pages>2</Pages><Words>341</Words><Characters>1948</Characters>
<Application>Microsoft Office Word</Application><DocSecurity>0</DocSecurity><Lines>16</Lines><Paragraphs>4</Paragraphs><ScaleCrop>false</Scale

and total time gives me this

VB.NET:
>42</TotalTime><Pages>2</Pages><Words>341</Words><Characters>1948</Characters><Application>Microsoft Office
 Word</Application>
<DocSecurity>0</DocSecurity><Lines>16</Lines><Paragraphs>4</Paragraphs><ScaleCrop>false</ScaleCrop><HeadingPairs><vt:vector size="2" baseType="variant

Why is it giving me so much extra i have to minus like 200+ from y to get what i want. I was never very good at strings but this doesn't make any sense.
 
Back
Top