strcmp date
#1

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

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}");
Reply
#3

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

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


Forum Jump:


Users browsing this thread: