Invert GMLscripts.com

string_rtrim

Returns given string with whitespace stripped from its end. Whitespace is defined as SPACE, LF, CR, HT, VT, FF. A string of characters to be trimmed may be optionally supplied.

//  string_rtrim(str, trim)
s = string_rtrim("123");                //  "123"
s = string_rtrim(" 123");               //  " 123"
s = string_rtrim("123 ");               //  "123"
s = string_rtrim(" 123 123 ");          //  " 123 123"
s = string_rtrim("123 \a ");            //  "123 \a"
s = string_rtrim("\t\r\n123\f \v");     //  "\t\r\n123"
s = string_rtrim("123456789", "1289");  //  "1234567"
string_rtrim(str, trim)
Returns given string with whitespace stripped from its end.
COPY/// @func   string_rtrim(str, trim)
///
/// @desc   Returns given string with whitespace stripped from its end.
///         Whitespace is defined as SPACE, LF, CR, HT, VT, FF. A string
///         of characters to be trimmed may be optionally supplied.
///
/// @param  {string}    str         string of text
/// @param  {string}    trim        characters to trim, optional
///
/// @return {string}    trimmed string
///
/// GMLscripts.com/license

function string_rtrim(str, trim=" \n\r\t\v\f")
{
    var l = 1;
    var r = string_length(str);
    while (string_pos(string_char_at(str, r), trim)) {
        r--;
    }
    return string_copy(str, l, r);
}

Contributors: xot

GitHub: View · Commits · Blame · Raw