| ||||||
Long String to ASCII Posted by neilvp (neilvp), 8 April 2005 In my application I receive a string back from the target that is an 8 byte string of hex values representing an 8 digit ascii string.e.g. 3938373635343332 = 98765432 and I want to display the 98765432 version. It occurs to me that there should be an elegant way of doing this. I have tried regsub but can't get it to work. Can anyone offer any hints as to how to do this please? Thanks Posted by admin (Graham Ellis), 9 April 2005 I think you want something like this (it's very similar to what we do on web pages to translate the hex codes or URL encodingregsub -all -nocase {([0-9a-f][0-9a-f])} $value \ {[format %c 0x\1]} value Posted by neilvp (neilvp), 11 April 2005 Oh Great Guru GrahamThanks for example, unfortunately I find that even this does not work in that it does not do as I would expect it to. My code # regsub1.tcl # TCL Script to test regsub # # 11 Apr 05 # # N Peers # # Idea is to convert a string of ascii values into a string # of ascii characters # e.g. 39383736 into 9876 set svalue 3938 regsub -all -nocase {([0-9a-f][0-9a-f])} $svalue \ {[format %c 0x\1]} svalue puts "String is now $svalue" The result % % source regsub1.tcl String is now [format %c 0x39][format %c 0x38] % % % Whereas I would expect it to put String is now 98 What am I doing wrong? Yours very frustratedly Neil Posted by admin (Graham Ellis), 11 April 2005 You're doing nothing wrong ... you're just short of the punchline because I failed to give it to you ...Code:
Prints Yes ! Posted by neilvp (neilvp), 13 April 2005 Apologies. Now I understand what the manual was saying all the time! A classic case of 'Read what is written, not what you think is written' Thank you. Posted by patthoyts (patthoyts), 18 April 2005 on 04/08/05 at 09:57:50, neilvp wrote:
set data [binary format H* $hexdata] This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
| ||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |