0

I have this text:

'\x0023AE1245F30B\x0000000000\x00CTRL-000,B01F00R03Z01\x00\x7f\x00\x00\n\x00\x00\x00\x00\x00\x00\x00P\x1d\xc9\xf0\xfd\x7f\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x1b\xe8K\xcfi\x7f\x00\x00V\x00\x00\x00\x00\x00\x00\x00 \x86\x80\xcfi\x7f\x00\x00P\x1d\xc9\xf0\xfd\x7f\x00'

How can I put off chars like \x00P?

I've tried with string.encode('UTF-8') But it's not working, throws me that error:

'ascii' codec can't decode byte 0xc9 in position 58: ordinal not in range(128)
Lluís M.
  • 80
  • 6
  • 2
    Then it's clearly not UTF-8. Did you consider UTF-16? – Ken White Apr 07 '17 at 21:56
  • @KenWhite if it was UTF-16 then every other byte would be `\x00`. This question is very unclear, I don't know what's being asked for here. – Mark Ransom Apr 07 '17 at 21:58
  • @MarkRansom: Yeah, I see that; I took a closer look at the crud that was posted that claimed to be *ASCII text*. It's definitely not some kind of string encoding, because none of them contain `\x00CTRL-000`,B01F00`. The poster needs to first figure out what they're trying to decode before attempting to decode it. (But I didn't say it was UTF-16. I pointed out that it clearly wasn't UTF-8, and that there were other encodings like UTF-16.) – Ken White Apr 07 '17 at 21:59
  • First of all You don't have text, You have stream of bytes. Now You can't encode string of bytes. You can decode them, so function decode would be better here. It is nice to remember that we **decode** bytes, and we **encode** into bytes. The challenge is that You don't know which coding is applied to your stream of bytes. I tried decoding this with 'Latin-1' and I received something, but without knowledge about coding there is not much You can do. – jedruniu Apr 07 '17 at 22:03
  • try with `new_variable = str(string)` – eyllanesc Apr 08 '17 at 02:03

0 Answers0