SA-MP Forums Archive
strcmp date - 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: strcmp date (/showthread.php?tid=616958)



strcmp date - MerryDeer - 13.09.2016

Hi,

I have string like that


05:20

It contains hours and minute.

how to change strcmp, i don't care is there is 05:20 or 5:20 or 05:2 or 05:20 or 5:2 i want that they always return that they are same


Re: strcmp date - Misiur - 13.09.2016

Split the string at ":", then use strval to retrieve specific parts. Using standard strcmp is not enough in this case. You'd need it to support regular expressions, but it doesn't, so you have it to do it by hand.

If you are using sscanf, you can just use it to validate it like two integers with ":" as a separating token:
pawn Код:
new success = !sscanf(anything, "p<:>{ii}");



Re: strcmp date - MerryDeer - 13.09.2016

So if i check if 05 equal to 5 it's will be equal?


Re: strcmp date - PrO.GameR - 13.09.2016

05 is equal to 5, so you could just easily use sscanf + strval
however 20 is not equal to 2, only the first cell is the same, so you could again use sscanf + first index of the string to check
PHP код:
new hour[3],minute[3];
sscanf(sth"p<:>s[3]s[3]",hour,minute);
return (
strval(hour)==5&&minute[0]=='2'); 
If your checks aren't static you need to use sscanf twice, and replace 5 and '2' with other variables your sscanf gave you.


However how this could be useful is beyond me!