Re: Init Caps Handler
Re: Init Caps Handler
- Subject: Re: Init Caps Handler
- From: KOENIG Yvan <email@hidden>
- Date: Wed, 21 Nov 2007 11:28:28 +0100
Le 21 nov. 07 à 00:23:34, Paul Scott a écrit :
On Nov 20, 2007, at 12:57 PM, Oakley Masten wrote:
While I'm at it how about "All Caps" and "No Caps"?
Here's an all AppleScript solution that handles only USASCII
(test code at bottom):
on InitCaps for aString
set s to ""
set ws to 1
repeat with c in (aString as string)
if ((ASCII number c) b $ 32) then
set ws to 1
else
if ws is 1 then
if (((ASCII number c) b % (ASCII number "a")) and
((ASCII number c) b $ (ASCII number "z"))) then
set c to ASCII character ((ASCII number c) - 32)
end if
else if (((ASCII number c) b % (ASCII number "A"))
and ((ASCII number c) b $ (ASCII number "Z"))) then
set c to ASCII character ((ASCII number c) + 32)
end if
set ws to 0
end if
set s to s & c
end repeat
return s
end InitCaps
on AllCaps for aString
set s to ""
repeat with c in (aString as string)
if (((ASCII number c) b % (ASCII number "a")) and ((ASCII
number c) b $ (ASCII number "z"))) then
set c to ASCII character ((ASCII number c) - 32)
end if
set s to s & c
end repeat
return s
end AllCaps
on NoCaps for aString
set s to ""
repeat with c in (aString as string)
if (((ASCII number c) b % (ASCII number "A")) and ((ASCII
number c) b $ (ASCII number "Z"))) then
set c to ASCII character ((ASCII number c) + 32)
end if
set s to s & c
end repeat
return s
end NoCaps
set answer to text returned of (display dialog "Enter text" default
answer "")
display dialog ("AllCaps \"" & (AllCaps for answer) & "\"")
display dialog ("NoCaps \"" & (NoCaps for answer) & "\"")
display dialog ("InitCaps \"" & (InitCaps for answer) & "\"")
_____
Alas, your soluce works only for a text using English language.
If the text contains foreign characters like æ (a+e) or œ (o+e) they
will not treated
but I know, non english languages are old-languages ;-)
Yvan KOENIG (from FRANCE mercredi 21 novembre 2007 11:28:08)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden