How do I distinguish between printable strings andpacked binary data stored as strings?
Dec 1st, 2004 09:09
Nat Tuck, flurpy flurp,
They're the same data type - there's no good way to tell them apart.
Optimally you should write your program so it knows what's going on and
gets data in a specific format when it expects data in that format.
If you really need to tell the difference between random binary data and
readable strings you'd be able to get a flakey result by checking to see
if any of the characters in the string have ascii values above 127 - if
so it's probably binary data. That has two problems: Some legitimate
characters such as accented characters may have values above 127 and
It's possible (1 in 2^#bytes in unbiased data) that you luck into binary
data with no values above 127.