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
#4
(Nov-29-2022, 06:12 PM)Larz60+ Wrote: Try this:
msgs = [
    b'\x01\x80Q\x01\x00\x01\x12\x00\x00\x80Test Message 12345',
    b'7\x00\x00\x00You find many blocks, can you send me some coin please!',
    b'\x01T\x00\x00\x80{"market":"2","rate":"2600","account":"ltc1q3la84qedyf2745y8cel4wklgqalsvh8xjk7g2k"}'
]

for msg in msgs:
    txt = str(msg).split('\\')[-1][3:-1]
    print(txt)
results:
Output:
Test Message 12345 You find many blocks, can you send me some coin please! {"market":"2","rate":"2600","account":"ltc1q3la84qedyf2745y8cel4wklgqalsvh8xjk7g2k"}

is it that easy? Man I'm the worst at splits.. can you talk through this? .split('\\')[-1][3:-1] looks like we split at \ then go back 3 what is the -1?
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, 06:50 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,346 Oct-14-2022, 07:48 AM
Last Post: Pedroski55
  Extract only certain text which are needed Calli 26 6,905 Oct-10-2022, 03:58 PM
Last Post: deanhystad
  Extract text rektcol 6 1,941 Jun-28-2022, 08:57 AM
Last Post: Gribouillis
  Can't strip extra characters from Data Canflyguy 7 2,084 Jan-10-2022, 02:16 PM
Last Post: Canflyguy
  Extract a string between 2 words from a text file OscarBoots 2 1,989 Nov-02-2021, 08:50 AM
Last Post: ibreeden
  Extract text based on postion and pattern guddu_12 2 1,763 Sep-27-2021, 08:32 PM
Last Post: guddu_12
  Extract specific sentences from text file Bubly 3 3,638 May-31-2021, 06:55 PM
Last Post: Larz60+
  extract color text from PDF Maha 0 2,161 May-31-2021, 04:05 PM
Last Post: Maha
Question How to extract multiple text from a string? chatguy 2 2,544 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