Skip to end of banner
Go to start of banner

Camel case function

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

Often times you may find yourself in need of generating camel case names. For example, if I wanted to programmatically create custom fields using SIL I could add SIL aliases for those custom fields at the same time. You want to avoid using spaces in alias names so a convention like camel case is an excellent habit to adopt.

function camelCase(string name) {
    string [] words = split(name, " ");
    string cc = toLower(words[0]);
    
    for(int x=1; x<size(words); x++) {
        string nextWord;
        for(int l=0; l<length(words[x]); l++) {
            if(l==0) {
                nextWord = toUpper(words[x][l]);
            } else {
                nextWord += words[x][l];
            }
        }
        cc += nextWord;
    }
    return cc;
}

return camelCase("I love using Power Scripts");

//returns iLoveUsingPowerScripts

  • No labels