Using sscanf like php explode
#1

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

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

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.
Reply
#4

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
Reply
#5

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+
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)