• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Routines for review: Hex <-> String
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: Routines for review: Hex <-> String
      • From: Paul Skinner <email@hidden>
References: 
 >Routines for review: Hex <-> String (From: julifos <email@hidden>)

  • Prev by Date: Re: Still cannot record anything in Script Editor
  • Next by Date: AppleScript Studio
  • Previous by thread: Re: Routines for review: Hex <-> String
  • Next by thread: Re: Routines for review: Hex <-> String
  • Index(es):
    • Date
    • Thread