Skip to content Skip to sidebar Skip to footer

Decoding A String In Python ... With _\x08__\x08_d\x08de\x08el\x08li\x08it\x08te\x08em In It

I have some strings with all this kind of characters in it which also has normal letters , and i want to transform all the 'wired' characters in they're normal representation . So

Solution 1:

Some (very old) bits of software used to simulate bold text on printers (such as daisy wheel of golfball typewriters) but printing a character then a backspace then the same character again. It looks like your text is an example of this.

That means you need to remove not just the backspace but also the character following it:

>>> s = "_\x08__\x08_d\x08de\x08el\x08li\x08it\x08te\x08em in it"
>>> import re
>>> re.sub("\x08.", "", s)
'__delitem in it'
>>> 

Better of course would be to fix whatever is generating this text and get it to generate bold text in a more useful manner.


Solution 2:

\x08 is the character representation for backspace.

So you should do a regexp replace

s/.\\x08//

That will remove all the \x08.

The \n is OK because it represents the end of the line.


Post a Comment for "Decoding A String In Python ... With _\x08__\x08_d\x08de\x08el\x08li\x08it\x08te\x08em In It"