I was hoping that LiveCode already had this function, but alas I can't find it. But, it does have the function "upper," which will convert a given text to all upper case. So, I used this to quickly build my own function to capitalize a given word:
The function takes a single word as input and puts it into the local variable w. So, let's imagine that the word entered was "nowhere."
The function begins by dissecting the given word into two parts: the first letter and the rest of the word. The first line takes the first character of w and puts it into another local variable x. So, in the case of "nowhere," x is equal to "n." The next line converts x to uppercase and puts the result in yet another local variable xupper. Great, we now have the first letter of the word capitalized. We now need to join this with the rest of the word
The next line takes note of the total number of characters in the word and puts this number in the variable L. Nowhere has seven characters, so L equals 7. The next line joins xupper ("N") to characters 2 to 7 of nowhere -- N+owhere -- resulting in "Nowhere" and puts this into y, which is then returned to whatever line of code called the function.
To demonstrate how to use this, I created a small stack with two fields and one button:
The left field is labeled "word1" and the field on the right is labeled "word2". The idea is that you type a word into the left field, press the button, and the word is capitalized and shown in the right field. Here's the script of the button "Capitalize":
The first line simply empties out field "word2." The second line takes whatever is in line 1 of the feld on the left and puts it into the local variable w1 (think of this as word 1).
The next line calls the capitalize function, puts the result into w2, which the next line puts into line 1 of the field on the right.
I added two more lines of code to tidy things up a little. I empty the field on the left and then I make sure that the focus (the flashing vertical text bar) is put into this field.
This function will be pretty darn handy in this and other LiveCode projects!