I'm running into a problem whenever I try to parse a text file by each line. I know I could use stream reader to read line by line but it is a lot easier to simply use split() and I would also like to know the reason why split() doesn't work.
For example, I created a file "test.txt" and filled it with the following text.
then put the following code in the load event of the form (a button click would work the same).
Code:
Dim str As String = My.Computer.FileSystem.ReadAllText(My.Computer.FileSystem.SpecialDirectories.Desktop & "\test.txt")
MsgBox("testforline" & str.Split(Environment.NewLine)(1))
The result is text2 appearing on the line below testforline. When using split, split is supposed to remove the character that was dividing the information as well however this isn't the case with new lines. How can I fix this? Also I tried using cchar() on environment.newline and controlchars.newline and neither worked.