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

Invert GMLscripts.com

string_rpos

Returns the right-most position of a substring within a string.

//  string_rpos(substr, str)
n = string_rpos("abc", "ABCabc");   //  4
n = string_rpos("ABC", "ABCabc");   //  1
n = string_rpos("XYZ", "ABCabc");   //  0
n = string_rpos("", "ABCabc");      //  0
n = string_rpos("XYZ", "");         //  0
n = string_rpos("", "");            //  0
string_rpos(substr, str)
Returns the right-most position of a substring within a string.
COPY/// @func   string_rpos(substr, str)
///
/// @desc   Returns the right-most position of a substring within a string.
///
/// @param  {string}    substr      substring of text
/// @param  {string}    str         string of text
///
/// @return {real}      position of substr
///
/// GMLscripts.com/license

function string_rpos(substr, str)
{
    var pos = 0;
    var ind = 0;
    do {
        pos += ind;
        ind = string_pos(substr, str);
        str = string_delete(str, 1, ind);
    } until (ind == 0);
    return pos;
}

Contributors: xot

GitHub: View · Commits · Blame · Raw