Got a string in ASCII (with only ASCII value ranges for A-Z, a-z, and " "), want to decode it.
ex. "781059910132" cooresponds to "Nice "
Is there an easy way to do this in Python 3?
Got a string in ASCII (with only ASCII value ranges for A-Z, a-z, and " "), want to decode it.
ex. "781059910132" cooresponds to "Nice "
Is there an easy way to do this in Python 3?
You can use regular expressions to extract 3- or 2-digit combinations:
import re
ascii_char = '[01]?\d\d'
s = '781059910132'
''.join(map(chr, map(int, re.findall(ascii_char, s))))
#'Nice '
This code works even with 0-padded codes:
''.join(map(chr, map(int, re.findall(ascii_char, '07832078'))))
#'N N'