Strtok

From SA-MP

Jump to: navigation, search

This is an implementation of the famous strtok function. To use it, copy and paste the code into your script.

strtok( const string[], &index, const seperator[] = " " )
{
	new
		index2,
		result[ 30 ];
 
	index2 =  strfind(string, seperator, false, index);
 
 
	if(index2 == -1)
	{
		if(strlen(string) > index)
		{
			strmid(result, string, index, strlen(string), 30);
			index = strlen(string);
		}
		return result; // This string is empty, probably, if index came to an end
	}
	if(index2 > (index + 29))
	{
		index2 = index + 29;
		strmid(result, string, index, index2, 30);
		index = index2;
		return result;
	}
	strmid(result, string, index, index2, 30);
	index = index2 + 1;
	return result;
}
Personal tools