-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathexplode.gml
More file actions
28 lines (27 loc) · 796 Bytes
/
Copy pathexplode.gml
File metadata and controls
28 lines (27 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/// @func 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;
}