Python Forum
extract only text strip byte array
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
extract only text strip byte array
#7
(Nov-29-2022, 08:10 PM)deanhystad Wrote: Your idea of stripping off non-printable characters is dangerous. The example below starts with bytes 0x1, 0x80, 0x51, 0x0. The danger is that 0x51 is the value of "Q". This "Q" is surrounded by other non-printable bytes, but what if it was just before "Test"? Unless you know that those leading bytes mean, you have to believe that potentially all the bytes could be printable and there won't be any "\" to look for.
Output:
b'\x01\x80Q\x01\x00\x01\x12\x00\x00\x80Test Message 12345'
I would do some research to find out what the leading bytes mean. The values probably tell you where the text starts. How did you get these bytes objects?

I did notice that the "prefix" bytes contain the length of the message.
b'\x01\x80Q\x01\x00\x01\x12\x00\x00\x80Test Message 12345' Message Length = b'\x12'
b'7\x00\x00\x00You find many blocks, can you send me some coin please!' Message Length = b'7'
b'\x01T\x00\x00\x80{"market":"2","rate":"2600","account":"ltc1q3la84qedyf2745y8cel4wklgqalsvh8xjk7g2k"}' Message Length = b'T'

the other bytes are info on what type of transaction this is, etc.. im pulling that off in other parts of the script and using it.. I just am too new and for some reason couldnt figure this out.. but im getting there.. slowly. :D
Reply


Messages In This Thread
extract only text strip byte array - by Pir8Radio - Nov-29-2022, 01:41 PM
RE: extract only text strip byte array - by Larz60+ - Nov-29-2022, 06:12 PM
RE: extract only text strip byte array - by Pir8Radio - Nov-29-2022, 09:55 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How do I add comments from a text-file to an array of folders? clausneergaard 2 1,939 Feb-08-2023, 07:45 PM
Last Post: Larz60+
Smile please help me remove error for string.strip() jamie_01 3 1,348 Oct-14-2022, 07:48 AM
Last Post: Pedroski55
  Extract only certain text which are needed Calli 26 6,926 Oct-10-2022, 03:58 PM
Last Post: deanhystad
  Extract text rektcol 6 1,952 Jun-28-2022, 08:57 AM
Last Post: Gribouillis
  Can't strip extra characters from Data Canflyguy 7 2,095 Jan-10-2022, 02:16 PM
Last Post: Canflyguy
  Extract a string between 2 words from a text file OscarBoots 2 1,996 Nov-02-2021, 08:50 AM
Last Post: ibreeden
  Extract text based on postion and pattern guddu_12 2 1,770 Sep-27-2021, 08:32 PM
Last Post: guddu_12
  Extract specific sentences from text file Bubly 3 3,645 May-31-2021, 06:55 PM
Last Post: Larz60+
  extract color text from PDF Maha 0 2,164 May-31-2021, 04:05 PM
Last Post: Maha
Question How to extract multiple text from a string? chatguy 2 2,547 Feb-28-2021, 07:39 AM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020