Reputation: 11
I have the following printed bytes returned from another system using sockets:
b"\x0bMessage Received!\r\x1c\r"
For example:
print(b"\x0bMessage Received!\r\x1c\r".decode(encoding="utf-8"))
And a I got
Can you help me to understand how to get an output like this Message Received!
from that message.
Upvotes: 1
Views: 390
Reputation: 55589
You need to strip out the unwanted characters (in this case vertical tab and carriage return):
>>> bs = b"\x0bMessage Received!\r\x1c\r"
>>> print(bs.decode().strip())
Message Received!
Upvotes: 2