By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,573 Members | 1,887 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,573 IT Pros & Developers. It's quick & easy.

Reading x characters from a file and parsing it.

P: n/a
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.
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

"Fred" <Fr**@NoWhere.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
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.

Nov 21 '05 #2

P: n/a
Fred,

When you not are looking for the method from Ken, than you probably can use
the readline method it reads everytime a line untill the crlf

http://msdn.microsoft.com/library/de...dLineTopic.asp

I hope this helps?

Cor

"Fred" <Fr**@NoWhere.com> .
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.

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.