/*
** Usage:
** size = explode_string(array,sep,data);
**
** Arguments:
** array name of a local array, string
** sep seperator character, string
** data array data, string
**
** Returns:
** size size of the array of data
**
** Notes:
** Converts a string of data with elements seperated
** by a delimiter into an array of strings.
**
** GMLscripts.com
*/
{
var arr,sep,dat,len,ind,pos;
arr = argument0;
sep = argument1;
dat = argument2 + sep;
len = string_length(sep);
ind = 0;
repeat (string_count(sep,dat)) {
pos = string_pos(sep,dat)-1;
variable_local_array_set(arr,ind,string_copy(dat,1,pos));
dat = string_delete(dat,1,pos+len);
ind += 1;
}
return ind;
}
String split function doesn't work in GMHtml5
Started by locohost, Dec 29 2011 04:08 AM
2 replies to this topic
#1
Posted 29 December 2011 - 04:08 AM
Here is the script. I've been using it for quite a while in GM8.1 code. However, now in GMHtml5, it's not working. Did something change about arrays or passing array refs to functions?
#2
Posted 29 December 2011 - 07:38 PM
the variable_local_array_set() function was removed in gm html5. all of the variable_* functions were removed.
#3
Posted 29 December 2011 - 07:53 PM
the variable_local_array_set() function was removed in gm html5. all of the variable_* functions were removed.
Thanks Gamer_Dude64. I found another string splitter that returns a ds_list. It's working
Here is the code for the next searcher...
/*
** Usage:
** string_parse(str,token,ignore_null)
**
** Arguments:
** str a string with a certain token seperating the
** desired substrings, string
** token a string (usually a single variable) representing
** the character(s) that str is seperated by, string
** ignore_null whether or not to include empty strings if, for
** example, the token was repeated, bool (true/false)
**
** Returns:
** a ds_list containing all substrings taken from str which
** were seperated by token.
**
** Example:
** string_parse("cat|dog|house|bee", "|", true);
** returns a ds_list containing "cat", "dog", "house", and "bee"
**
** GMLscripts.com
*/
{
var str, token, ignore, list, tlen, temp;
str = argument0;
token = argument1;
ignore = argument2;
list = ds_list_create();
tlen = string_length( token);
while( string_length( str) != 0) {
temp = string_pos( token, str);
if( temp) {
if( temp != 1 || !ignore)
ds_list_add(list, string_copy(str, 1, temp - 1));
str = string_copy( str, temp + tlen, string_length( str));
}
else {
ds_list_add(list, str);
str = "";
}
}
return list;
}
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











