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

Invert GMLscripts.com

explode

Returns an array of strings parsed from a given string of elements separated by a delimiter.

names = "Juliett,Victor,Mike,Charlie,Romeo,Oscar";

array = explode(",", names);

//  array[0] == "Juliett"
//  array[1] == "Victor"
//  array[2] == "Mike"
//  array[3] == "Charlie"
//  array[4] == "Romeo"
//  array[5] == "Oscar"
explode(del, str)
Returns an array of strings parsed from a given string of elements separated by a delimiter.
COPY/// explode(del, str)
///
/// @desc   Returns an array of strings parsed from a given
///         string of elements separated by a delimiter.
///
///         eg. explode(":", "hello:world") == ["hello", "world"]
///
/// @param  {string}    del         delimiter character(s)
/// @param  {string}    str         group of elements
///
/// @return {array}     array of strings
///
/// GMLscripts.com/license

function explode(del, str)
{
    if (str == "") return [str];
    if (del == "") return [str];
    str += del;
    var arr = array_create(0);
    var len = string_length(del);
    repeat (string_count(del, str)) {
        var pos = string_pos(del, str) - 1;
        array_push(arr, string_copy(str, 1, pos));
        str = string_delete(str, 1, pos + len);
    }
    return arr;
}

Contributors: xot

GitHub: View · Commits · Blame · Raw