I have byte arrays like this:
[77, 83, 65, 80, 79, 67, 32, 32, 32, 32, 32, 32, 32]
approximately equal
[M , S, A, P, O, C, , , , , , , ] when printed as chars.
Now I want to trim the trailing spaces so that they look like this:
[77, 83, 65, 80, 79, 67]
The easiest way to do this?
Change I do not want to deal with strings, because there is a possibility for non-printable bytes, and I can not afford to lose this data. These should be byte arrays :( Whenever I do a conversion to strings, bytes like 01 (SOH) 02 (STX), etc. are lost.
Edit 2 : Just for clarification. Am I losing data if I convert byte arrays to strings? Now a little confused. What if bytes have a different character set?
java
Dominic Bou-Samra
source share