GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2017-11-23 03:16:03

ryuzaki_mrl
Member
Registered: 2017-11-23
Posts: 1

string_split

Expand/// string_split(str, substr)
/* Description: divides string "str" at delimiter "substr" and
    returns an array containing all of the pieces. */

var str = argument0, sub = argument1, result, i = 0, pos = string_pos(sub, str);

while(pos) {
    result[i++] = string_delete(str, pos, string_length(str));
    str = string_delete(str, 1, pos);
    pos = string_pos(sub, str);
}
result[i] = str;

return result;

Example code:

Expandvar words = string_split("the sky is blue", " ");
show_debug_message(words[1]); // This will output "sky"

Offline

#2 2018-01-18 07:33:25

gnysek
Member
Registered: 2011-12-29
Posts: 36

Re: string_split

should be:

Expand}
if (str != "") {
    result[i] = str;
}

return result;

in case of "the sky is blue ".

Offline

Board footer

Powered by FluxBB