By Daniel · December 24, 2008
Breaks apart a string into a list of pieces separated by delimiter
// string_explode(delimiter, subject)
// Breaks apart a string into a list of pieces separated by delimiter
// delimiter: the string which separates each piece
// subject: the string to break apart
var delimiter, len, subject, result, pos, piece;
delimiter = argument0;
len = string_length(delimiter);
subject = argument1;
result = ds_list_create();
while (true) {
pos = string_pos(delimiter, subject);
if (pos == 0) { // no delimiters left
ds_list_add(result, subject);
break;
}
piece = string_copy(subject, 1, pos-1);
ds_list_add(result, piece);
subject = string_delete(subject, 1, string_length(piece) + len);
}
return result;
Categories: String handling
There are no comments to display.
You must be signed in to post comments.