I have a simple program that someone helped me write--thus I don't completely understand it--that reads in text records and outputs excel records. Up until now, I have been reading in simple text records which were all 12 bytes long, so I'm using this code to read them in:
' Open the stream and read it back.
Dim fs As FileStream
fs = File.Open(strSourceFile, FileMode.Open, FileAccess.Read)
'record length plus 1 here
Dim b(14) As Byte
Dim temp As UTF8Encoding = New UTF8Encoding(True)
Dim strLine As String
Do While fs.Read(b, 0, b.Length) > 0
strLine = temp.GetString(b)
As you can see, we are dimensiong 'b' as 14, which takes into consideration the 12 byte record plus the CrLf at the end of the record.
The problem is that I now need to be able to read in variable length records; some will be 6, while other are 12. Both record types will end in CrLf.
Is there a simple way to build my string by reading data until I come to the CrLf, rather than having to use a fixed length as shown above? I need an example that a rookie can understand, if possible.