Convert lowercase text to uppercase

What would be the way to convert a lowercase text string to uppercase? Is there an uppercase function?

'bbbbb' to 'BBBBB'

Thanks in advance

iMac g5, Mac OS X (10.4.7)

Posted on Aug 11, 2006 4:34 AM

Reply
8 replies

Aug 11, 2006 7:14 AM in response to dev_sleidy

Thank You - I enhanced it a bit to ignore numbers and other characters - Works like a charm.....

set lower CaseString to "abd*&^&%^%ebewhjfvefe"

set upper CaseString to ""
repeat with i in lower CaseString
if (ASCII number i) > 96 and (ASCII number i) < 123 then
set upper CaseString to upper CaseString & (ASCII character ((ASCII number i) - 32))
else
set upper CaseString to upper CaseString & (ASCII character (ASCII number i))
end if
end repeat

upper CaseString

Aug 11, 2006 8:18 AM in response to Bruce Kirman

Re-written, to reduce the number of 'ASCII number i' calls.

set lower CaseString to "a1bd*&^&%^%e3bew5hjfv4efe"

set upper CaseString to ""
repeat with I in lower CaseString
set ascii_i to (ASCII number I)

if ((ascii_i > 96) and (ascii_i < 123)) then
set upper CaseString to upper CaseString & (ASCII character (ascii_i - 32))
else
set upper CaseString to upper CaseString & (ASCII character ascii_i)
end if
end repeat

upper CaseString<br>
Mac OS X (10.4.4)

Aug 12, 2006 2:06 AM in response to Bruce Kirman

I have been using these set of handlers for a few years now. Much faster than calling Standard Additions.

on lowercaseString(theString)
set upperCaseChars to "ABCDEFGHIJKLMNOPQRSTUVWXYZÆŒØ∏ÁÀÂÄÃÅÇÉÈÊËÍÌÎÏÑÓÒÔÖÕÚÙÛÜŸ"
set lowerCaseChars to "abcdefghijklmnopqrstuvwxyzæœøπáàâäãåçéèêëíìîïñóòôöõúùûüÿ"
considering case
repeat with i from 1 to theString's length
set testChar to character i of theString
if testChar is in upperCaseChars then
set theString to getString(testChar, theString, upperCaseChars, lowerCaseChars)
end if
end repeat
end considering
return theString
end lowercaseString

on uppercaseString(theString)
set upperCaseChars to "ABCDEFGHIJKLMNOPQRSTUVWXYZÆŒØ∏ÁÀÂÄÃÅÇÉÈÊËÍÌÎÏÑÓÒÔÖÕÚÙÛÜŸ"
set lowerCaseChars to "abcdefghijklmnopqrstuvwxyzæœøπáàâäãåçéèêëíìîïñóòôöõúùûüÿ"
considering case
repeat with i from 1 to theString's length
set testChar to character i of theString
if testChar is in lowerCaseChars then
set theString to getString(testChar, theString, lowerCaseChars, upperCaseChars)
end if
end repeat
end considering
return theString
end uppercaseString

on getString(testChar, theString, searchList, replaceList)
set {oldDelims, AppleScript's text item delimiters} to ¬
{AppleScript's text item delimiters, {testChar}}
set charOffset to (length of (text item 1 of searchList)) + 1
set textItems to text items of theString
set theChar to (character charOffset of replaceList)
set AppleScript's text item delimiters to {theChar}
set theString to textItems as string
set AppleScript's text item delimiters to oldDelims
return theString
end getString

Aug 12, 2006 8:44 PM in response to Bruce Kirman

Bruce,

instead of using a pure AppleScript function which does character-by-character translation (which will be slow), you might want to consider a mixed AppleScript/shell script variant - the tr utility is pretty much what you are looking for...

The following script has three handlers which will convert to uppercase, lowercase, or change the case of each letter:

Click to open this script in your Script Editor <pre style="font-family: 'Monaco', 'Courier New', Courier, monospace; overflow:auto; padding: 0.2em; font-size: 10px; width:500px">set theString to "This is an example input string"

log upperCase(theString)
log lowerCase(theString)
log changeCase(theString)

on upperCase(theString)
do shell script "echo " & quoted form of theString & " | tr '[a-z]' '[A-Z]'"
end upperCase

on lowerCase(theString)
do shell script "echo " & quoted form of theString & " | tr '[A-Z]' '[a-z]'"
end lowerCase

on changeCase(theString)
do shell script "echo " & quoted form of theString & " | tr '[A-Za-z]' '[a-zA-Z]'"
end changeCase</pre>

Andreas User uploaded file

Aug 13, 2006 12:28 AM in response to Andreas Amann

Hello Andreas

Your script is efficient but only for those who never use accented chars.
If the argument string contains accented chars as frequently used in euopean languages, they would not be converted.
I know that this is frequent with shell tools but from my point of view, it's time to enhance these tools.

Yvan KOENIG (from FRANCE dimanche 13 août 2006 09:29:00)

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Convert lowercase text to uppercase

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.