Re: Routines for review: Hex <-> String
Re: Routines for review: Hex <-> String
- Subject: Re: Routines for review: Hex <-> String
- From: Paul Skinner <email@hidden>
- Date: Fri, 17 Jan 2003 13:51:00 -0500
I like this.
set hex to stringtoHex("hello world")
-->{"68", "65", "6c", "6c", "6f", "20", "77", "6f", "72", "6c", "64"}
set AppleScript's text item delimiters to "%"
HexToString("%" & hex)
-->"hello world"
set AppleScript's text item delimiters to ""
on stringtoHex(s)
words 2 thru ((length of s) + 1) of (do shell script "echo " & s & " |
hexdump -C")
end stringtoHex
on HexToString(h)
do shell script "echo " & h & " | perl -ple
's/%([0-9a-fA-F]{2})/chr(hex($1))/ge' "
end HexToString
credit for the perl goes to interiot as posted at
http://www.experts-exchange.com/Operating_Systems/Unix/Q_20095807.html
and to google for hooking me up!
--
Paul Skinner
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.