You are currently viewing the GMLscripts.com static mirror. Forum access and script submissions are not available through this mirror.

Invert GMLscripts.com

string_ucwords

Returns a string with the first character capitalized.

s = string_ucwords("hello, world!");    //  "Hello, World!"
s = string_ucwords("hello,\nworld!");   //  "Hello,\nWorld!"
s = string_ucwords("hello,\tworld!");   //  "Hello,\tWorld!"
s = string_ucwords("HELLO, WORLD!");    //  "HELLO, WORLD!"
s = string_ucwords("12345");            //  "12345"
s = string_ucwords("");                 //  ""
string_ucwords(str)
Returns a string with each word capitalized.
COPY/// @func   string_ucwords(str)
///
/// @desc   Returns a string with each word capitalized.
///
/// @param  {string}    str         string of text
///
/// @return {string}    capitalized string
///
/// GMLscripts.com/license

function string_ucwords(str)
{
    var out = "";
    var w = true;
    var i = 1;
    repeat (string_length(str)) {
        var c = string_char_at(str, i);
        var o = ord(c);
        if ((o > 8) && (o < 14) || (o == 32)) {
            w = true;
        }else{
            if (w == true) c = string_upper(c);
            w = false;
        }
        out += c;
        i++;
    }
    return out;
}

Contributors: xot

GitHub: View · Commits · Blame · Raw