Page 1 of 1

Title Case

Posted: Sat Jun 22, 2013 3:43 pm
by sandybassett
I had this is another thread but think I should start a new one for it.
Craig, I think you are telling me that there is no TitleCase function in LiveCode and I had better resurrect an ancient coding technique into LC language to roll my own. Maybe something like-separate chunks delineated by space, put each chunk toLower, get 1st char of each chunk & put toUpper, merge chunks back together. If that's right, since I would be using this on most all input fields, I should make it a function and put it somewhere? so as to have it available for including in every stack I create? N'est pas?

Before spending some time on this, am I on the right track or is there some other way? Thanks for the help.

Re: Title Case

Posted: Sat Jun 22, 2013 3:57 pm
by Klaus
Hi Sandy,

pardon my ignorance, but what does a "TitleCase" "function" do? 8-)


Best

Klaus

Re: Title Case

Posted: Sat Jun 22, 2013 6:31 pm
by sandybassett
TitleCase (sometimes called Mixed Case) puts the first letter of each word in uppercase and the rest of the word in lowercase. Very convenient for input of names of people, addresses, cities, books, etc especially when the user is low on grammatical skills and can just type everything in lowercase and have the program 'fix it' for him.

Re: Title Case

Posted: Sat Jun 22, 2013 6:33 pm
by Dixie
Then look at 'toUpper' in the dictionary...
for example...

Code: Select all

on mouseUp
   put toLower( fld 1) into fld 1
   repeat with count = 1 to the number of words of fld 1
      put toUpper( char 1 of word count of fld 1) into char 1 of word count of fld 1
   end repeat
end mouseUp

Re: Title Case

Posted: Sat Jun 22, 2013 7:07 pm
by Klaus
EX-ACTLY! :-)

Re: Title Case

Posted: Sat Jun 22, 2013 7:48 pm
by FourthWorld
It may be helpful to add a list of words to leave as lower-case, like "of", "an", and", etc.

Re: Title Case

Posted: Sat Jun 22, 2013 9:53 pm
by sandybassett
OK thanks guys; I'll try Dixie's code first and adapt from there if necessary. So my 2nd question was about best practices I guess. Since you can drag any existing stack into the one you're working on, would you keep various scripts in a master file and copy the desired ones to the current stack, or is there a better way to avoid re-inventing the wheel with every program?