ASCII file without crlf's

  • Thread starter Thread starter Andrew
  • Start date Start date
A

Andrew

Hello. I am working with very large files in my .NET project (1
million plus records). Some of these files do not have crlf's, which
makes it very hard to read the file without a layout or record length.
In my application, I would like to open one of these text files and
check to see if it contains crlf's before proceeding in my code. I
tried using the streamreader, but readline() cancels out with a memory
error because it thinks the ENTIRE file is first record since there
are no crlf's. I have also tried FSO, but I get a server timeout.

Is there any easy way to check for crlf's with files like this?

Thanks!
 
Open the file and instead of using readline, just use read passing 1 as length.
Compare that single character as a vbCr or vbLf. If you *must* check for vbCrLf,
you should watch out because sometimes they are backwards, vbLf & vbCr.

Hope this helps,
Mythran
 
Use a BinaryReader, and read in say 128 bytes at a time - vByteArray =
vBinReader.ReadBytes(128)
Then check the array for bytes of value 10 or 13 - or as Mythran says,
combinations of 10, 13, 10 & 13 or 13 & 10.
_____________________________
The Grim Reaper
 
thanks guys for you help. works great now.

Dim fs As System.IO.FileStream = New
System.IO.FileStream("C:\upload\cas001-987607\input.txt",
IO.FileMode.Open)

Dim vByteReader As System.IO.BinaryReader = New
System.IO.BinaryReader(fs)

Dim byteArray() As Byte
ReDim byteArray(128)

byteArray = vByteReader.ReadBytes(128)

....

from here, i will check the array byteArray(i) for the different
cases.

thanks.
 
Back
Top