Re: AsciiNumber & AsciiCharacter Handlers
Re: AsciiNumber & AsciiCharacter Handlers
- Subject: Re: AsciiNumber & AsciiCharacter Handlers
- From: has <email@hidden>
- Date: Tue, 7 May 2002 02:16:31 +0100
Paul Skinner wrote:
>
Here's a pair of handlers that might be interesting to those having
>
to call Ascii Number or Ascii Character a lot. [...]
You can easily avoid all the nastiness of typing strings containing control
and high-ASCII characters directly into your script. Try the following
(I've also added error trapping):
======================================================================
on initAllTextCharacters()
set chars to ""
repeat with i from 0 to 255
set chars to chars & (ASCII character i)
end repeat
end initAllTextCharacters
-- [init this property at compile-time]
property allTextCharacters : initAllTextCharacters()
--
on asciiCharacter(theInteger)
try
return item (theInteger + 1) of allTextCharacters
on error
error "Invalid parameter for asciiCharacter()."
end try
end asciiCharacter
on asciiNumber(theCharacter)
try
set oldTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to theCharacter
set ind to length of (first text item of allTextCharacters)
set AppleScript's text item delimiters to oldTID
if ind is 256 then error
return ind
on error
error "Invalid parameter for asciiNumber()."
end try
end asciiNumber
======================================================================
[Which reminds me: I really need to sort out the incomplete, incoherent
mess that is conversionLib sometime... it has a whole bunch of functions
for this sort of stuff...]
HTH
has
--
http://www.barple.connectfree.co.uk/ -- The Little Page of Beta AppleScripts
_______________________________________________
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.