Re: Convert first char to lower case
Re: Convert first char to lower case
- Subject: Re: Convert first char to lower case
- From: Paul Berkowitz <email@hidden>
- Date: Mon, 07 Jan 2002 18:54:57 -0800
On 1/7/02 6:28 PM, "Nigel Garvey" <email@hidden>
wrote:
>
Olivier Berquin wrote on Mon, 07 Jan 2002 15:20:03 +0100:
>
>
> Hello everybody,
>
>
>
>
>
> I wrote this handler, but I'm not sure that it's very powerfull.
>
> It convert the first character of a var to lower case.
>
>
>
>
'ASCII number' and 'ASCII character' can be quite slow if you have to use
>
them a lot. In AppleScript, it's more convenient to look for the first
>
character in an alphabetical string of the upper-case characters, and to
>
replace it with the same-numbered character from a lower-case string.
>
<snip>
>
if (class of Variable1 is string) and ((count Variable1) > 0) then
>
set upperChars to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
>
set lowerChars to "abcdefghijklmnopqrstuvwxyz"
>
-- 'offset' is case-sensitive
>
set alphaPos to the offset of (character 1 of Variable1) in
>
upperChars
Nigel,
Knowing you, you've probably tested this. But is 'offset ' that much faster
than ASCII number? It's also an osax. Wouldn't it be quicker yet to use text
item delimiters, which are also case-sensitive, and much faster?
set AppleScript's text item delimiters to {character 1 of Variable1}
set alphaPos to (count (text item 1 of upperChars)) + 1
set AppleScript's text item delimiters to {""}
If you're in OS 9 , with 'the ticks' available, would you like to try
repeating the two versions 1000 times to check? (And if you were repeating
1000 times, you could even just reset tids once at beginning and end, if
that made much difference, which it probably won't.
--
Paul Berkowitz