1

I'm trying to log a bluetooth connection in an Android app (non-malicious, it's logging diagnostics). However, the transmissions and responses are in byte arrays and contain non-ASCII bytes. Trying to log the raw byte array gives about 20 spaces between every other character.

How can I remove all non-ASCII bytes?

2 Answers 2

2

Iterate through the byte array and append each byte that is in the ASCII range to a StringBuilder. Remember to cast them to char such that you get append(char) rather than append(int).

Sign up to request clarification or add additional context in comments.

Comments

0

Since you are bothering to log the data at all perhaps you should log the hex-encoding of the data. That way you'll preserve all the information present. If you really want to see only the ASCII characters you can post-process the log information to give you an ASCII view of it when you want.

1 Comment

What it is. That's the deeper question. However, since this is on a phone, I can't exactly do much post-processing. I'm most likely not going to have access to the machines where the data is viewed.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.