SA-MP Forums Archive
sscanf split function - 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: sscanf split function (/showthread.php?tid=610032)



sscanf split function - NeXoR - 19.06.2016

Well yeah, I have been working with sscanf along with ZCMD but I never used sscanf as a splitter
I mean, as a replacement for split()
Could anyone guide me how to do this ?

For example:
Код:
%s | %s | %s | %s
How can I fetch those strings into variables using split ?
I ******d split() and I know how to do this, but the SAMP Wiki is saying that SSCANF is way smarter and faster

Anyone ?


Re: sscanf split function - Jf - 19.06.2016

This?

PHP код:
main()
{
    new
        
mainStr[50] = {"This|Is|An|Example"}, // Main string which stores the data.
        
splittedStr[4][20]; // Splitted result.
    
sscanf(mainStr"p<|>s[20]s[20]s[20]s[20]"splittedStr[0], splittedStr[1], splittedStr[2], splittedStr[3]); // Delimiter '|' - 4 strings.
    
printf("%s %s %s %s"splittedStr[0], splittedStr[1], splittedStr[2], splittedStr[3]); // This will print "This Is An Example".




Re: sscanf split function - NeXoR - 19.06.2016

Quote:
Originally Posted by Jf
Посмотреть сообщение
This?

PHP код:
main()
{
    new
        
mainStr[50] = {"This|Is|An|Example"}, // Main string which stores the data.
        
splittedStr[4][20]; // Splitted result.
    
sscanf(mainStr"p<|>s[20]s[20]s[20]s[20]"splittedStr[0], splittedStr[1], splittedStr[2], splittedStr[3]); // Delimiter '|' - 4 strings.
    
printf("%s %s %s %s"splittedStr[0], splittedStr[1], splittedStr[2], splittedStr[3]); // This will print "This Is An Example".

Exactly, thanks pal