On Tue, 8 Mar 2022 21:15:42 +0100, R.Wieser wrote:
>
> Yes, and no*. But I am afraid I was a bit to quick with my reply, making
> assumptions I should not have. "mid(...)" doesn't work. JJ, my
> apologies.
Hold on there, I didn't know that VB can convert Byte() to a string. In this
case, MID() can actually be used.
e.g. if the Byte() array contains:
F1, F2, F3, F4, F5, F6
hex(ascw(mid(arr, 1, 1))) would be F2F1.
hex(ascw(mid(arr, 2, 1))) would be F4F3.
hex(ascw(mid(arr, 3, 1))) would be F6F5.
But since MID() only accept a string, the Byte() value must be converted to
a string first, so for performance's sake, if this method is used
(especially in a loop), MID() should use a string which was preconverted.
Since I notice that VBScript can't(won't?) convert the last byte of an odd
length Byte() into a UTF-16 character (FYI, JScript can), a different method
must be used.
e.g. if the Byte() array contents is:
F1, F2, F3, F4, F5
len(arr) would only be 2. So, we can't use MID(arr, 3, 1).
Instead, we use RIGHT(), which unexpectedly, works. i.e.:
hex(ascw(right(arr, 1))) would be F5F4.
I was expecting it to be F4F3 because I assumed that it works just like
MID(), but I was wrong. It actually retrieve the last two bytes from the end
of the array, instead of from the last even index of the array.
So, thank you for mentioning MID().