Difference between revisions of "User:Peter Stindberg/strCapitalize"

From Second Life Wiki
Jump to navigation Jump to search
m (Peter Stindberg moved page User:Peter Stindberg/Code to User:Peter Stindberg/strCapitalize: Better name)
m
 
Line 2: Line 2:
{{LSL_Function
{{LSL_Function
|func=strCapitalize
|func=strCapitalize
|func_desc=This function will take a string as input and return the string with the first letter of each word capitalized and all the other letters in lowercase. <syntaxhighlight lang="lsl">string strCapitalize(string str)
|func_desc=Created by [[User:Peter Stindberg|Peter Stindberg]], this function will take a string as input and return the string with the first letter of each word capitalized and all the other letters in lowercase. <syntaxhighlight lang="lsl">string strCapitalize(string str)
{
{
     list phrase = llParseStringKeepNulls(str, [" "], []);
     list phrase = llParseStringKeepNulls(str, [" "], []);

Latest revision as of 21:04, 8 July 2022

Summary

Function: string strCapitalize( string str );

Created by Peter Stindberg, this function will take a string as input and return the string with the first letter of each word capitalized and all the other letters in lowercase.
string strCapitalize(string str)
{
    list phrase = llParseStringKeepNulls(str, [" "], []);
    integer i;
    for (i = 0; i < llGetListLength(phrase) ; i++) {
        phrase = llListReplaceList(phrase, [llToUpper(llGetSubString(llList2String(phrase,i),0,0)) + llToLower(llGetSubString(llList2String(phrase,i),1,-1))], i, i);
    }
    return llDumpList2String(phrase, " ");
}

Returns a string with each word capitalized.
• string str Word or phrase that will be capitalized.

Caveats

Will fail with acronyms since all letters but the first will be turned to lowercase.

Examples

Deep Notes

Signature

function string strCapitalize( string str );