1

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.

1
  • Try this, print(b"\x0bMessage Received!\r\x1c\r".replace(b'\x0b', b'').decode(encoding="utf-8")) Commented Mar 5, 2020 at 12:03

2 Answers 2

2

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!
Sign up to request clarification or add additional context in comments.

Comments

-1
b"\x0bMessage Received!\r\x1c\r".decode("utf-8")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.