• 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: Mon, 30 Dec 2002 10:54:25 -0500

> Date: Thu, 26 Dec 2002 23:53:20 -0500
> To: email@hidden
> From: Hudson Barton <email@hidden>
> Subject: Hex String Handlers
>
> I have a little routine to convert an ascii string into its hex
> equivalent, and another to reverse the process. It is very slow on
> anything but the smallest text segment. I'm wondering if there is
> any "Terminal" or shell alternative. No osaxen please. The "hex"
> handler is below.

> on HexString(AString)

[snip]


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
set h to ""
repeat with c in s
set text item delimiters to c
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
return h
end StringToHex

StringToHex("abc") --> "616263"



This is also interesting:

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"


Also, X-Commands from kanzu.com has a string to hex method, and
many other nice things... :)

<http://www.kanzu.com>


{ 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.

  • Prev by Date: Re: Scripting system preferences in OS X 10.2.3
  • Next by Date: associate a file extension with an app
  • Previous by thread: Re: Hex String Handlers
  • Next by thread: Re: Hex String Handlers
  • Index(es):
    • Date
    • Thread