B4J Question Beware of the TRIM function cutting more than Spaces

Starchild

Active Member
Licensed User
Longtime User
I was chasing a protocol issue in some software. I was receiving ASCII serial data and applied the TRIM function to the received packet. I discovered that not only were the Trailing spaces removed from the data (expected) but it also stripped the trailing character (03) being an ETX in ASCII. This caused me problems with decoding the rest of the ASCII data packet.

I haven't done further testing to see if it also trims other non-visible characters in the ASCII set, but be aware, it's not just trimming spaces as the function's description suggests.
 

emexes

Expert
Licensed User
if it also trims other non-visible characters

I knew it also trimmed Tabs, but didn't realise it trimmed other characters too. šŸ¤”

Just tested, and it trims all characters ASCII 0 (NUL) thru to 32 (space).

Interestingly, it doesn't trim ASCII 127 (DEL), but maybe that's not regarded as a control character in Unicode.

Nor does it trim any of the Unicode special spaces (non-breaking, thin, half, zero-width, etc).

Apparently you and I were just a tiny bit behind the times šŸ¤£ :

Trim removes all the characters that are considered as white space characters. This includes all characters with code point smaller than 21.

The 21 is technically correct, but I feel it would have been better as "code point 32 and smaller".
 
Last edited:
Upvote 0
Top