sscanf split function
#1

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 ?
Reply
#2

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".

Reply
#3

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)