SA-MP Forums Archive
Splitting strings using strtok at another character - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Splitting strings using strtok at another character (/showthread.php?tid=124146)



Splitting strings using strtok at another character - theRealG - 29.01.2010

Hello,

I want to split strings with strtok, not at a space, but on a random character, lets say ",".

Код:
new_strtok(const string[], &index){
	new length = strlen(string);
	while ((index < length) && (string[index] <= ','))
	{
		index++;
	}

	new offset = index;
	new result[20];
	while ((index < length) && (string[index] > ',') && ((index - offset) < (sizeof(result) - 1)))
	{
		result[index - offset] = string[index];
		index++;
	}
	result[index - offset] = EOS;
	return result;
}
Works perfectly fine but it still splits strings at spaces too. How can I fix that?


Re: Splitting strings using strtok at another character - mansonh - 29.01.2010

Your using string[index] <= ','
My guess is that " " is > ","

maybe try string[index] != ','


Re: Splitting strings using strtok at another character - theRealG - 29.01.2010

Doesnt work either...


Re: Splitting strings using strtok at another character - theRealG - 29.01.2010

Wrote my own one.
If anyone has the same prob and needs help just reply or PM me.