Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Changing case of text string

Changing case of text string
Thread Tools
Dedicated MacNNer
Join Date: May 2000
Location: Chattanooga, TN
Status: Offline
Reply With Quote
Jun 2, 2000, 09:54 PM
 
I need a way to take a text input from the user and convert it to all caps for use. Specifically, the script prompts the user for a name then creates a folder with that name. For the sake of uniformity, I need the folder name to be in all caps. Any suggestions?
     
Forum Regular
Join Date: Mar 2000
Location: toronto, canada
Status: Offline
Reply With Quote
Jun 2, 2000, 11:16 PM
 
Try using the ASCII commands in the Standard Additions dictionary.

example:

Code:
set file_name to "blah-BLAH-blah-234" set new_file_name to convertToCaps(file_name) log new_file_name on convertToCaps(x) set z to {} repeat with a in (characters of x) set b to ASCII number a if b > 96 and b < 123 then set b to b - 32 set end of z to (ASCII character b) as text else set end of z to a as text end if end repeat return z as string end convertToCaps
returns
(*BLAH-BLAH-BLAH-234*)

There's probably a more efficient method. Visit MacScripter.net to see if there's anything better.

Happy Applescripting!

Here's a list of results using the ASCII number command:

"a"--> 97 "A"--> 65
"b"--> 98 "B"--> 66
"c"--> 99 "C"--> 67
"d"--> 100 "D"--> 68
"e"--> 101 "E"--> 69
"f"--> 102 "F"--> 70
"g"--> 103 "G"--> 71
"h"--> 104 "H"--> 72
"i"--> 105 "I"--> 73
"j"--> 106 "J"--> 74
"k"--> 107 "K"--> 75
"l"--> 108 "L"--> 76
"m"--> 109 "M"--> 77
"n"--> 110 "N"--> 78
"o"--> 111 "O"--> 79
"p"--> 112 "P"--> 80
"q"--> 113 "Q"--> 81
"r"--> 114 "R"--> 82
"s"--> 115 "S"--> 83
"t"--> 116 "T"--> 84
"u"--> 117 "U"--> 85
"v"--> 118 "V"--> 86
"w"--> 119 "W"--> 87
"x"--> 120 "X"--> 88
"y"--> 121 "Y"--> 89
"z"--> 122 "Z"--> 90

[This message has been edited by lycaon (edited 06-03-2000).]
     
Forum Regular
Join Date: Mar 2000
Location: toronto, canada
Status: Offline
Reply With Quote
Jun 3, 2000, 12:05 AM
 
Hello again,

If you go to MacScripter.net and search for a script called "TitleCase" by Arthur J. Knapp, you'll see a better implementation of replacing characters using ASCII commands and text item delimiters (be sure to read up on text item delimiters first if you've never used them). You should be able to adapt part of it to your needs.

Have fun!

[This message has been edited by lycaon (edited 06-03-2000).]
     
tonymac  (op)
Dedicated MacNNer
Join Date: May 2000
Location: Chattanooga, TN
Status: Offline
Reply With Quote
Jun 3, 2000, 03:34 AM
 
I appreciate the prompt responses. However, I seem to have answered my own question. I found a scripting addition called "Kamprath's Text Utilities" on www.osaxen.com. It allows several conversions on text strings including all upper case, all lower case, and title case. It worked perfectly. Since all the machines running the script will have access to a common file server, I added a sub routine to check for the existence of the addition. If it's missing the routine will attempt to install it from the server. If it fails, the the script will skip the capitalization command altogether.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 11:05 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2