LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
kpeters
- Posts: 112
- Joined: Wed Mar 21, 2007 9:32 pm
Post
by kpeters » Thu Jun 21, 2007 2:57 am
TIA for any suggestions of improvement for the following little function.
Kai
Code: Select all
function ProperCase pString
local caps, tmp
--
put True into caps
repeat for each char C in pString
if caps then
put toUpper( C ) after tmp
else
put toLower( C ) after tmp
end if
put ( C is in " ,-." ) into caps # stop chars go here
end repeat
return tmp
end ProperCase
-
Mark
- Livecode Opensource Backer

- Posts: 5150
- Joined: Thu Feb 23, 2006 9:24 pm
-
Contact:
Post
by Mark » Fri Jun 22, 2007 10:53 am
Dear Kai,
I believe the following is what you want:
Code: Select all
function ProperCase pString,pCaps
local tmp
if pCaps is not true then put false into pCaps --empty?
if pCaps then put toUpper(pString) into tmp
else put toLower(pString) into tmp
repeat for each char myChar in " ,-."
replace myChar with empty in tmp
end repeat
return tmp
end ProperCase
You could also use replaceText(tmp,"[, .-]",empty) instead of the repeat loop, but that is not necessarily faster and is slightly more complex.
Best,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
-
kpeters
- Posts: 112
- Joined: Wed Mar 21, 2007 9:32 pm
Post
by kpeters » Sun Jun 24, 2007 12:38 am
Hi Mark - thanks for your reply. Your code does something quite different from mine, though.
Mine intends to (as the function name suggests) propercase a string, i.e. turn something like "DR. alBERT scHWEItzer" into "Dr. Albert Schweitzer"
and I am wondering if you might have suggestions as to how to improve
my code for that purpose.
Regards,
Kai
-
Klaus
- Posts: 14190
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Mon Jun 25, 2007 3:45 pm
Hi kai,
your code looks great to me, couldn't be scripted to run faster
Best
Klaus