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

Re: Hex String Handlers


  • Subject: Re: Hex String Handlers
  • From: "Arthur J. Knapp" <email@hidden>
  • Date: Tue, 31 Dec 2002 11:18:24 -0500

> Date: Mon, 30 Dec 2002 10:54:25 -0500
> Subject: Re: Hex String Handlers
> From: "Arthur J. Knapp" <email@hidden>


I wrote:

> Try this:
>
> property ksHex : "0123456789ABCDEF"
> property ks256 : run script "
> set a to {}
> repeat with i from 0 to 255
> set a's end to ascii character i
> end
> return a as string"
>
> on StringToHex(s)
> set t to text item delimiters

Some more recent versions of AppleScript seem to require that
the "of AppleScript" syntax is always required with the text item
delimiters, so:

set t to AppleScript's text item delimiters


> set h to ""
> repeat with c in s
> set text item delimiters to c

It has recently been brought to my attention that some versions
of AppleScript are not going to behave as I would expect them to
in the above. It is safer to explictly coerce the "c" from the
"c in s" statment to a string before assigning it to the text
item delimiters:

repeat with c in s
set AppleScript's text item delimiters to (c as string)

> set i to ks256's text item 1's length
> set h to h & ,
> ksHex's item (i div 16 + 1) & ,
> ksHex's item (i mod 16 + 1)
> end repeat
> set text item delimiters to t

set AppleScript's text item delimiters to t

> return h
> end StringToHex



> set str to "abc"
>
> try
> err of (str as Pascal string)
> on error m
> end try
> m's text from -((str's length) * 2 + 2) to -3 --> "616263"

I neglicted to mention a very obvious limitation of the above,
namely, that a Pascal string can only contain 255 characters of
text, so:

on StringToHex(s)

set c to s as C string

try
err of c
on error msg
end try

return msg's text -((s's length) * 2 + 4) thru -5

end

I would appreciate any feed back from users of OSX as to whether
or not this StringToHex() handler works for them, thank you.


{ Arthur Knapp, of <http://www.STELLARViSIONs.com>
a r t h u r @ s t e l l a r v i s i o n s . c o m

"Safe the Nature" - political graffiti in Prague
}
_______________________________________________
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: Hex String Handlers
      • From: Paul Berkowitz <email@hidden>
  • Prev by Date: Re: EPS information
  • Next by Date: Re: Hex String Handlers
  • Previous by thread: Re: Hex String Handlers
  • Next by thread: Re: Hex String Handlers
  • Index(es):
    • Date
    • Thread