Compare Byte Array and String

  • Thread starter Thread starter KenKrugh
  • Start date Start date
K

KenKrugh

Guest
I'm new to vb.net and trying to add to someone else's existing code.

They're opening a file binary (I think) as such:

fs = New FileStream(TheFnt.FName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
CharsReadTst = fs.Read(DatRead, 0, 10)


I want to check the first 5 characters at the start of the file. Using the read statement above I tried converting the byte array I read from the file to a string but I'm having not luck despite trying all the possible encodings:

DatReadStr = System.Text.Encoding.Unicode.GetString(DatRead)
If DatReadStr <> ChrW(&H4F) & ChrW(&H54) & ChrW(&H54) & ChrW(&H4F) & ChrW(&H0) Then

I also tried going the other way and creating a byte array to compare against the file read above, but again, no joy:

OTSig = System.Text.Encoding.Unicode.GetBytes(ChrW(&H4F) & ChrW(&H54) & ChrW(&H54) & ChrW(&H4F) & ChrW(&H0))
if DatRead.SequenceEqual(OTSig) then

I could open the file a second time and read as text but the program will be reading 6,000+ files on a regular basis and I'm trying to keep it as fast as possible and minimize disk access.

Thanks very much for reading,
Ken

Continue reading...
 
Back
Top