Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
Convert hexadecimal characters to ascii
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="John Machin, post: 3688856"] What you have is the output of the repr() function, which gives an unambiguous representation in printable ASCII of the string, with the extra bonus that it's a valid Python string constant that can be used in code to produce exactly the same value. What your example means is: the string contains 's', a backspace, a space, and a backspace, followed by 'Test!'. Try this at the Python interactive prompt: | >>> q = 's\x08 \x08Test!' | >>> len(q) | 9 Note there are only 4 characters infront of 'Test!' | >>> q | 's\x08 \x08Test!' What you have looks like very raw keyboard input: s oops space oops T e etc Pardon the pedantry, but you don't need to "get rid of any hexadecimal characters" ... hexadecimal characters are 01234567890ABCDEFabcdef :-) I guess that what you would like to do is simulate the keyboard processing of backspaces: | >>> def unbs(strg): | ... stack = [] | ... for c in strg: | ... if c == '\x08': | ... if stack: | ... stack.pop() | ... else: | ... stack.append(c) | ... return ''.join(stack) | ... | >>> unbs(q) | 'Test!' BTW, '\b' means the same as '\x08'; saves keystrokes when testing. | >>> unbs('abc\b\b\bxyz!\b') | 'xyz' HTH, John [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
Convert hexadecimal characters to ascii
Top