• 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: ASCII
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ASCII


  • Subject: Re: ASCII
  • From: "Arthur J Knapp" <email@hidden>
  • Date: Thu, 18 Jan 2001 17:44:48 -0500

> Is there a command to convert to hex? I know how to make a script for it, but
> a single command would be easier

Not with vanilla AppleScript. I know that Eric Grant's scripting
addition, "Sigma's Coercions" has such a command:

<http://www.eagrant.com/Sigmas-Coercions.sit.hqx>

and I'm sure many others do as well. Check out scriptweb.com, (if
it's still there).


Here is my rather interesting way to do it. Most of the
time, it would be a bit silly to use it, but I suspect that
if you have a really BIG string to convert, this may be one
of the fastest vanilla solutions around, despite the amount
of code involved:


to hexify_via_file(str)

-- Create a temporary file
--
set temp_file to (("" & (path to temporary items)) & "ThrowAway")
set temp_ref to (open for access file temp_file write permission (true))

-- Write, then read back as data
--
write str to temp_ref
set str to (read temp_ref from 1 as data)
--
--> +data rdat416243644566476849;

-- Close and delete temporary file
--
close access temp_ref
ignoring application responses -- don't wait for the damn AppleEvent
tell application "Finder" to delete file temp_file
end ignoring

try
foo of str -- purposely cause an error
on error err
--
-- err = "Can't get foo of +data rdat416243644566476849;."
set str to text 28 thru -3 of ("" & err)
end try

-- str = "416243644566476849"

-- Optional parsing of string into list
--
set lst to {}
repeat with x from 1 to ((str's length) - 1) by 2
set lst's end to str's text x thru (x + 1)
end repeat


return lst -- {"41", "62", "43", "64", ...}

end hexify_via_file

hexify_via_file("AbCdEfGhI")



If you choose to use this, I will accept both Visa and Master Card
for my royalties...

;-)

--
{
Arthur J Knapp, of STELLARViSIONs ;

http://www.STELLARViSIONs.com ;

mailto:email@hidden ;

"... but I could be anyone"
"No you couldn't, sir ..."
}


  • Follow-Ups:
    • Re: ASCII
      • From: Emmanuel <email@hidden>
  • Prev by Date: Modals?
  • Next by Date: Re: OSAX within tells
  • Previous by thread: Re: ASCII
  • Next by thread: Re: ASCII
  • Index(es):
    • Date
    • Thread