Title Text

Devin Asay devin_asay at byu.edu
Wed Oct 27 12:34:51 EDT 2010


On Oct 27, 2010, at 10:21 AM, Alex Adams wrote:

> Is there a function that I can use to convert a string to title text (the
> first letter of each word is capitalized)?  I can¹t find one in the
> dictionary.  I could write a handler I suppose, but I¹m hoping there is
> something already available.

Alex,

Here's a really basic one I have used. It actually let's you choose between sentence case and title case with an optional argument. But there is no checking for words that shouldn't be capitalized according to English capitalization rules, such as prepositions. But it's a start.

function capitalize string,allWds
    if allWds is true then
        put number of words in string into limit
    else 
        put 1 into limit
    end if
    repeat with i = 1 to limit
        put toUpper(char 1 of word i of string) into char 1 of word i of string
    end repeat
    return string
end capitalize

Regards,

Devin


Devin Asay
Humanities Technology and Research Support Center
Brigham Young University




More information about the Use-livecode mailing list