Reading x characters from a file and parsing it.

  • Thread starter Thread starter Fred
  • Start date Start date
F

Fred

I have a text file that has records in it 801 characters long with | as a
separator between fields in the records (no CRLF between fields). I know I
can use the split method to separate out the data once I've read it in. But
how can I get the data in. It seems like the only thing I can do is read it
in as a byte/char array and then concatenate the values to make a string.
Nothing that returns a string seems to be able to let me specify how much
data to read.

Any suggestions would be greatly appreciated.
 
Hi,

The code below should put the 801 charachters into a string for you. Don't
forget to import System.IO.

Dim fs As New FileStream(mstrFilePath, FileMode.Open, FileAccess.Read)
Dim sReader As New StreamReader(fs)
Dim arrChar() As Char
Dim strData As String
sreader.Read(arrChar, (801 * (intRecordNumber - 1), 801)
strData = arrChar

Good luck! Ken.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top