What is the best way to parse a string of bytes, that do not have a delimiter? What I have is a string of bytes received by the Serial Port that I need to decode. There are anywhere from 10 to 255 bytes in a string.
I’d appreciate thoughts on the matter.
What are you parsing it for? In other words, what do you expect to find in each string?
Each char is a byte of data. Some are printable like ‘<’ some contain non-printable characters wherein each bit is meaningful.
I am using the Mid function now to put into an array. But for some reason, I thought that there was/is a better way that you have mentioned in another post. Unfortunately I cannot recall what year or the name given to the technique/method/function you suggested another.
Use split without a split character.
Using split without a delimiter will parse on a byte by byte (or char by char) basis? Is this by design or bug? I did not see this in the docs so it makes me think that maybe it is an “undocumented feature”.
Put it into a memoryblock and access that byte by byte
I do not found it @ developer
Except use SplitB to work with bytes instead of text. Or, as Jeff said, use a MemoryBlock.
dim mb as MemoryBlock = myData
dim p as Ptr = mb
dim lastBytePos as integer = mb.Size - 1
for bytePos as integer = 0 to lastBytePos
dim b as byte = p.Byte( bytePos )
// do something with b
If you’re looking for speed, that’s probably the fastest way.
If you’re going to be moving sequentially through the string to parse it, consider using a BinaryStream which you can load directly from a string, or a memory block is another good approach. Both allow you to ready a variety of data types directly.
An array of bytes is good if you truly want to access each byte individually, and potentially in a random fashion.
There used to be a bug that this won’t work one some non-English locale systems. I had reports from Japanese users that this failed, years ago. I am sure I reported this as a bug but don’t think it ever got resolved as I checked a while later it was still not addressed.
So be careful with this unless you have confirmation it is fixed.
Ah, here it is: feedback://showreport?report_id=16190