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 17:24:01 -0500
Has kindly pointed out, off list, that my stringToHex fails with more
than 16 characters. Doh!
Sooo...
on stringtoHex(s)
set hexData to paragraphs of (do shell script "echo " & s & " |
hexdump -C")
set AppleScript's text item delimiters to ""
set hex to ""
repeat with thisVal in hexData
try
set hex to hex & text 11 thru 59 of thisVal
end try
end repeat
return words 1 thru -2 of hex
end stringtoHex
: ( there goes my one-liner.
--
Paul Skinner
On Friday, January 17, 2003, at 01:51 PM, Paul Skinner wrote:
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.