[RESOLVED] Confusing File read issue
Hey, I'm trying to read a file line by line into an array but It skips the item at index: 3 I have it msgboxing just to make sure and it wont even touch it. any help is appreciated
Code:
Dim Btn As Button = DirectCast(sender, Button)
Dim path As String = Application.StartupPath & "\Libraries\" & Btn.Text.Replace(" ", "_") & ".ipt"
Dim i As Integer = 0
Dim lines As String() = IO.File.ReadAllLines(path)
Dim arraymorph(lines.Length) As String
Dim ReadMorphs As New IO.StreamReader(path)
While ReadMorphs.Peek() <> -1
MsgBox(ReadMorphs.ReadLine.ToString())
arraymorph(i) = ReadMorphs.ReadLine
i += 1
End While
textfile contents =
@ALWAYSREPLACE
a:4
t:7
textissue
e:3
just wont touch texttissue
Thanks again
Sumn3rd
Re: Confusing File read issue
You're calling ReadLine() twice. It'll read two lines per loop.
Code:
While ReadMorphs.Peek() <> -1
Dim Str As String = ReadMorphs.ReadLine()
MsgBox(Str)
arraymorph(i) = Str
i += 1
End While
Re: Confusing File read issue
Pssh I left that there from when I was debugging it and still used it to test it. Turns out the method I was using to debug it was rooting it. Haha ironic. Thankyou
Re: [RESOLVED] Confusing File read issue
I don't understand it. In the following line you have already read all text lines from your file:
Code:
Dim lines As String() = IO.File.ReadAllLines(path)
Why do you read them again into the arraymorth line by line?