Search code examples
vb.nettextfilestream

Reading a part of a txt file in VB.NET


I need to read a txt file part by part... For example, in a txt file: (age,5char_name)

17susan23wilma25fredy

I need to read firstly 17susan. In other words, the first seven characters and after 23wilma and 25fredy, but I'm not reading the whole file and substring the file record. Is there a way to do this via streamreader?

Records are always seven bytes... 2 bytes for age, 5 bytes for name and all records in a line. There is no jump into the next line.


Solution

  • I think there is the solution:

    Dim filestream As New FileStream("\records.txt", FileMode.Open)
    Dim streamreader As New StreamReader(fs)
    Dim buffer(7) As Char
    bw.ReadBlock(buffer, 0, 7)
    Console.WriteLine(buffer)
    

    this is read first 7.. you can read other via loop or for..