Invert GMLscripts.com

string_stagger_case

Returns a string with the letters in staggered case, such as: "hElLo! hOw ArE yOu ToDaY?"

//  string_stagger_case(str, spaces, first)
s = string_stagger_case("this is a test", false, false);    //  "tHiS iS a TeSt"
s = string_stagger_case("this is a test", true, false);     //  "tHiS Is a tEsT"
s = string_stagger_case("this is a test", false, true);     //  "ThIs Is A tEsT"
s = string_stagger_case("this is a test", true, true);      //  "ThIs iS A TeSt"
s = string_stagger_case("this is a test");                  //  "ThIs iS A TeSt"
string_stagger_case(str, spaces, first)
Returns a string with the letters in staggered case, such as: "hElLo! hOw ArE yOu ToDaY?"
COPY/// @func   string_stagger_case(str, spaces, first)
///
/// @desc   Returns a string with the letters in staggered case,
///         such as: "hElLo! hOw ArE yOu ToDaY?"
///
/// @param  {string}    str         string of text
/// @param  {bool}      spaces      count spaces as letters (default true)
/// @param  {bool}      first       capitalize first letter (default true)
///
/// @return {string}    string in stagger case
///
/// GMLscripts.com/license

function string_stagger_case(str, spaces=true, first=true)
{
    var len = string_length(str);
    var old = "";
    for (var j=1; j<=len; j++) {
        if (string_char_at(str, j) == " " && spaces == false) continue;
        if (first) old = string_upper(string_char_at(str, j));
        else       old = string_lower(string_char_at(str, j));
        str = string_delete(str, j, 1);
        str = string_insert(old, str, j);
        first = !first;
    }
    return str;
}

Contributors: Legolas710, xot

GitHub: View · Commits · Blame · Raw