Link to home
Start Free TrialLog in
Avatar of jskfan
jskfanFlag for Cyprus

asked on

IndexOf and Substring in VB.Net

on this code below regarding Form1_Load, i would like someone to explain to me this part of it:

----------------------------------------
sCurrentBook = BookStreamReader.ReadLine
            iPosition1 = sCurrentBook.IndexOf("|") + 1
            iPosition2 = sCurrentBook.IndexOf("|", iPosition1) + 1
            Book.Code = sCurrentBook.Substring(0, iPosition1 - 1)
            Book.Title = sCurrentBook.Substring(iPosition1, iPosition2 - iPosition1 - 1)
            Book.Price = sCurrentBook.Substring(iPosition2)
Note: book is a variable of Structure and the structure is not shown in this code.

-----------------------------------------



Private Sub Form1_Load(ByVal sender As Object, _
            ByVal e As System.EventArgs) Handles MyBase.Load
        Dim BookStreamReader As StreamReader
        Dim sCurrentBook As String
        Dim iPosition1, iPosition2 As Integer
        BookFileStream = New FileStream(sPath, FileMode.Open, FileAccess.Read)
        BookStreamReader = New StreamReader(BookFileStream)
        Do Until BookStreamReader.Peek = -1
            sCurrentBook = BookStreamReader.ReadLine
            iPosition1 = sCurrentBook.IndexOf("|") + 1
            iPosition2 = sCurrentBook.IndexOf("|", iPosition1) + 1
            Book.Code = sCurrentBook.Substring(0, iPosition1 - 1)
            Book.Title = sCurrentBook.Substring(iPosition1, iPosition2 - iPosition1 - 1)
            Book.Price = sCurrentBook.Substring(iPosition2)
            Books.Add(Book)
            cboBooks.Items.Add(Book.Title)
        Loop
        BookStreamReader.Close()
        btnUpdate.Enabled = False
        btnCancel.Enabled = False
    End Sub
ASKER CERTIFIED SOLUTION
Avatar of lostcarpark
lostcarpark

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial