Greetings,
I have looked thru the archives and I cannot seem to locate some code I know I have seen. In a program, I am loading a Binary Buffer and want to know before I start processing the contents of the buffer if it contains any Binary Data as opposed to strict Ascii text data. I believe the example I saw was by Tony but not positive.
Anyone have a reliable way of determining if the buffer contains Binary Data in excess of 7Fh?
Thanx,
Keith
Not sure. Looked in my archives and found code to look for @LF (char2num(10)) for text binary data. Maybe looking for char2num( < 127 ), although sure Tony will reply.
The most reliable method is to check each byte value to ensure that it is in the range of an ASCII character.
An alternative would be to randomly sample a percentage of byte values. That approach is less reliable but more efficient if the buffer is large enough.
A third approach would be to use the BinaryIndexEx function to repeatedly search for character values that our outside of expected text values.
Quote from: td on October 09, 2025, 01:09:07 PMA third approach would be to use the BinaryIndexEx function to repeatedly search for character values that our outside of expected text values.
That gets my vote, and I apologize - I meant >127 not <127 in my response. How that might be done would be interesting, but dependent on your original goal. Loading a binary buffer and...
- Do not process further if high ascii value found
- Iterate all instances of high ascii values and decide from there
- Re-encode and continue
WB has a super supply of binary functions. Using CLR with .Net StreamReader() might be an option for re-coding, but has issues.
I think with a little more information about the source and goal, your ask could be accomplished.
[EDIT]
you can also consider loading as ADODB.Stream with charset as "UTF-8" ' or "ISO-8859-1"
Of course, if loading a binary buffer from a file, one can simply use the FileEncoding function to determine whether the file and therefore buffer is ANSI text.
Quote from: td on October 10, 2025, 08:17:28 AMOf course, if loading a binary buffer from a file, one can simply use the FileEncoding function to determine whether the file and therefore buffer is ANSI text.
And, of course, of course... these threads can often leader to a function not immediate in memory. Op might not like the sideshow, but appreciate you mentioning the function.
Yup. I didn't think of the function when I first read the OP's post. There is a certain amount of irony in that lapse.
Tony,
Thanx for the heads up regarding FileEncoding() not something I had ever used in the past.
My greatest issue is that I do not get to play around day in/day out with tools like this to really learn them. I deal with the heat of a moment issue and then it may be months before I come back to the tool in the next crises situation.
BinaryBuffers are definitely a cool feature, something I had wanted to get into quite some time back but not had the opportunity. I remember seeing some code where the programmer was scanning the buffer for codes (in excess of >127) but have not been able to locate that code again to save my bacon. I figured that searching for (>127) and (<8) (2 passes of the buffer) would present most situation where you did not want to deal with binary data as text, yes I know there is a range above LF and below SP that is not normally considered text and the top and bottom checks above would most likely make the 3rd range not necessary to check.
I appreciate the assistance... thanx !!
Keith