SA-MP Forums Archive
Using sscanf like php explode - 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)
+--- Thread: Using sscanf like php explode (/showthread.php?tid=619828)



Using sscanf like php explode - Kruzz - 22.10.2016

Hello! I was wondering if there's any method to use sscanf like the php explode (some synthax which doesn't limit the identifiers; basically not a fixed amount of identifiers). I've searched for a while but I wasn't able to find anything at all. Is there such a method?
Thanks!


Re: Using sscanf like php explode - Kaliber - 22.10.2016

Yes..you can use sscanf for this...
Look at
PHP код:
"p<|>" 



Re: Using sscanf like php explode - Kruzz - 22.10.2016

So, the usage will be something like this?
PHP код:
sscanf(string"p<|>", array); 
Assuming that array is obviously the array to store the results into.


Re: Using sscanf like php explode - denNorske - 22.10.2016

Yes

Don't forget that the arrays would be receiving each "part" of the Split string, so keep enough space to store em' all. I thought there was a place to read the documentation, but it has been taken down (it seems).

Good luck


Re: Using sscanf like php explode - Kruzz - 23.10.2016

So... it doesn't work.

That's the code I've runned for testing:
PHP код:
new array[15][32];
sscanf("test|test_2|test_3""p<|>", array);
    
printf("array[0]: %s", array[0]);
printf("array[1]: %s", array[1]);
printf("array[2]: %s", array[2]); 
And that's the messages I've got in the console:

PHP код:
[12:49:26sscanf warningFormat specifier does not match parameter count.
[
12:49:26] array[0]: 
[
12:49:26] array[1]: 
[
12:49:26] array[2]: 
// edit: it works now

Code:
PHP код:
new array[15][32];
sscanf("test|test_2|test_3""p<|>a<s[32]>[15]", array);
    
printf("array[0]: %s", array[0]);
printf("array[1]: %s", array[1]);
printf("array[2]: %s", array[2]);
printf("array[3]: %s", array[3]); // obviously, array[3] should be empty 
Output:

PHP код:
[12:51:31] array[0]: test
[12:51:31] array[1]: test_2
[12:51:31] array[2]: test_3
[12:51:31] array[3]: 
Thanks for your help. rep+