jazzwhistle
Member
- Joined
- Oct 17, 2006
- Messages
- 7
- Programming Experience
- 1-3
You cannot read a binary file into a string - why would you want to?
Well for example, you might have a binary file that contains some ascii and you may be looking for a certain sequence of bytes in order to process the file. You can't use Contains or Substring with a byte array as far as I know, so I've been having a similar problem.
You have to use ReadAllBytes to read binary files as a byte array (GetString stops, as you say, with 0's), and then you can loop through it to build your string using "&" or a StringBuilder.Append, or, even nicer you can use BitConverter.ToString(yourbytearray).
Which brings me to My question... for small files that is all fine, but for a 125kb file (not huge...) the concatenating takes ages
StringBuilder.Append works much faster than concantenating with &, but I still need to convert the stringbuilder back to a string at some point in order to use Contains and SubString later on to process the file - at which point the StringBuilder.ToString takes forever!
I'd be very grateful if anyone has any ideas why this takes so long, or how else I should be approaching the problem.
Cheers