GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 Script Submission » string_split » 2017-11-23 03:16:03

ryuzaki_mrl
Replies: 1
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"

Board footer

Powered by FluxBB