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!
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
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
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.