• 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: Convert first char to lower case
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Convert first char to lower case


  • Subject: Re: Convert first char to lower case
  • From: Nigel Garvey <email@hidden>
  • Date: Tue, 8 Jan 2002 02:28:25 +0000

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.

If a 'return' occurs as the result of an 'if' line, there's actually no
need for an 'else' section, as what follows can only be executed if the
'return' isn't. (But there's nothing to stop you including 'else' for
clarity if you prefer.)

You don't need to count the 'characters' of a string. Just count the
string. The characters will be counted by default and it will happen
faster.

--
set myName to "This character"
-- bla bla bla
set myName to ConvertFirstCharToLowerCase(myName)

on ConvertFirstCharToLowerCase(Variable1)

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

if (alphaPos > 0) then
if ((count Variable1) = 1) then return (character alphaPos of
lowerChars)
return (character alphaPos of lowerChars) & (text 2 thru -1 of
Variable1)
end if
end if

return Variable1
end ConvertFirstCharToLowerCase

NG


  • Follow-Ups:
    • Re: Convert first char to lower case
      • From: Paul Berkowitz <email@hidden>
  • Prev by Date: Re: AppleScript Distribution Legalities
  • Next by Date: Re: Convert first char to lower case
  • Previous by thread: Re: Convert first char to lower case
  • Next by thread: Re: Convert first char to lower case
  • Index(es):
    • Date
    • Thread