Extracting string to different variables
#1

So, basically i've got a variable date that stores time in "dd/mm/yyyy hh:mms" format, and i need to extract each part in it's own variable (dd goes to day, mm goes to month, yy goes to year etc..)
So, how can i do it?
Reply
#2

Using str* functions (strmid, strdel, strfind, ...).
Reply
#3

You can use sscanf with optional delimiters.

PHP код:
new date[16] = "10/15/2018 22:35"
    
daymonthyearhourminuter;
sscanf(date"P< :/>iiiii"daymonthyearhourminute); 
This will scan the string for the optional delimiters : space, colon, forward slash
Not sure if this is fully correct but a variation of this should work.

https://sampforum.blast.hk/showthread.php?tid=570927
Reply
#4

As for str... functions, you might want to do it as following:
Relocate the data in buffer variable, detect the slash, copy everything you had there in separate variable, delete the copied item with a slash from the variable, and so on with checking proper chars (be it / or : ). Must be enough, but it might not be as beautiful as sscanf variation of approach.
Reply
#5

Quote:
Originally Posted by Maxandmov
Посмотреть сообщение
As for str... functions, you might want to do it as following:
Relocate the data in buffer variable, detect the slash, copy everything you had there in separate variable, delete the copied item with a slash from the variable, and so on with checking proper chars (be it / or : ). Must be enough, but it might not be as beautiful as sscanf variation of approach.
He must use sscanf as AdamsLT said ; it's better and faster. I didn't thought about it in first time.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)