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=610126)



strcmp date - ScIrUsna - 20.06.2016

Hi,

I use strcmp to check strings and i need to check if player input text is contain date my data form is ex: 2016-06-20 but i want to make if player write 2016-(without zero)6-20 it's still found as strcmp they are same


Re: strcmp date - Vince - 20.06.2016

Split with sscanf. Or use a regular expression.


Re: strcmp date - ScIrUsna - 20.06.2016

Can give example?


Re: strcmp date - kaZax - 20.06.2016

For format: M/D/YY, M/D/YYY, MM/DD/YY, MM/DD/YYYY
Код HTML:
^((0?[13578]|10|12)(-|\/)(([1-9])|(0[1-9])|([12])([0-9]?)|(3[01]?))(-|\/)((19)([2-9])(\d{1})|(20)([01])(\d{1})|([8901])(\d{1}))|(0?[2469]|11)(-|\/)(([1-9])|(0[1-9])|([12])([0-9]?)|(3[0]?))(-|\/)((19)([2-9])(\d{1})|(20)([01])(\d{1})|([8901])(\d{1})))$
You can use: https://sampforum.blast.hk/showthread.php?tid=609570


Re: strcmp date - jlalt - 20.06.2016

You can use this function I've just wrote it and tested it worked well. .-.

Usage Example:
PHP код:
      new date[25] = "2016-06-20";
   if(
CheckDateSame(date,"2016-6-20")) {
      
printf("They Are Same");
   }
   else
   {
      
printf("They Are Not Same");
   } 
PHP код:
CheckDateSame(date1[25], date2[25]) {
   if(!
strcmp(date1date2true))
   {
      return 
1;
   }
   else
   {
      new 
number[3][20],area1 strfind(date1"-"true0)+1;
      
strmid(number[0], date10area1-1);
      
strmid(number[1], date1area1strfind(date1"-"truearea1));
      
area1 strfind(date1"-"truearea1)+1;
      
strmid(number[2], date1area1strlen(date1));
      new 
number1[3][20];
      
area1 strfind(date2"-"true0)+1;
      
strmid(number1[0], date20area1-1);
      
strmid(number1[1], date2area1strfind(date2"-"truearea1));
      
area1 strfind(date2"-"truearea1)+1;
      
strmid(number1[2], date2area1strlen(date2));
      if(
strval(number[0]) == strval(number1[0]) && strval(number[1]) == strval(number1[1]) && strval(number[2]) == strval(number1[2]))
      {
          return 
1;
      }
      else
      {
          return 
0;
      }
   }




Re: strcmp date - ScIrUsna - 20.06.2016

What if date i want to compare is string that player can input and it's can by any text? it's not going to crash?


Re: strcmp date - Konstantinos - 20.06.2016

If the player inputs a date only either by a command or dialog input:
pawn Код:
new y, m, d;
if (sscanf(inputtext, "p<->iii", y, m, d)) return ... // error for not inputting a valid date
// "params" if it is a command instead of "inputtext"
If you want to check about date inside a whole text, use regex as above users mentioned.


Re: strcmp date - ScIrUsna - 20.06.2016

Can i use 2 sscanf in one command?


Re: strcmp date - Konstantinos - 20.06.2016

Sure you can but the order and the way you use it matters if you want a command to have completely different parameters.


Re: strcmp date - ScIrUsna - 20.06.2016

CheckDateSame(date1[25], date2[25]) {

Can i use without [25] because i get (error arrays size do not match)


Re: strcmp date - jlalt - 20.06.2016

Quote:
Originally Posted by ScIrUsna
Посмотреть сообщение
CheckDateSame(date1[25], date2[25]) {

Can i use without [25] because i get (error arrays size do not match)
be sure your string / date handler having the same size of this function codes.


Re: strcmp date - ScIrUsna - 21.06.2016

This mean i have to make bigger string in function and it have to by bigger i will use?

Код:
CheckDateSame(date1[], date2[]) {
   if(!strcmp(date1, date2, true))
   {
      return 1;
   }
   else
   {
      new number[3][80],area1 = strfind(date1, "-", true, 0)+1;
      strmid(number[0], date1, 0, area1-1);
      strmid(number[1], date1, area1, strfind(date1, "-", true, area1));
      area1 = strfind(date1, "-", true, area1)+1;
      strmid(number[2], date1, area1, strlen(date1));
      new number1[3][80];
      area1 = strfind(date2, "-", true, 0)+1;
      strmid(number1[0], date2, 0, area1-1);
      strmid(number1[1], date2, area1, strfind(date2, "-", true, area1));
      area1 = strfind(date2, "-", true, area1)+1;
      strmid(number1[2], date2, area1, strlen(date2));
      if(strval(number[0]) == strval(number1[0]) && strval(number[1]) == strval(number1[1]) && strval(number[2]) == strval(number1[2]))
      {
          return 1;
      }
      else
      {
          return 0;
      }
   }
}
I make new number 80 bytes that means my date1 or date2 have to by smaller than 80 bytes?


Re: strcmp date - jlalt - 21.06.2016

Quote:
Originally Posted by ScIrUsna
Посмотреть сообщение
This mean i have to make bigger string in function and it have to by bigger i will use?

Код:
CheckDateSame(date1[], date2[]) {
   if(!strcmp(date1, date2, true))
   {
      return 1;
   }
   else
   {
      new number[3][80],area1 = strfind(date1, "-", true, 0)+1;
      strmid(number[0], date1, 0, area1-1);
      strmid(number[1], date1, area1, strfind(date1, "-", true, area1));
      area1 = strfind(date1, "-", true, area1)+1;
      strmid(number[2], date1, area1, strlen(date1));
      new number1[3][80];
      area1 = strfind(date2, "-", true, 0)+1;
      strmid(number1[0], date2, 0, area1-1);
      strmid(number1[1], date2, area1, strfind(date2, "-", true, area1));
      area1 = strfind(date2, "-", true, area1)+1;
      strmid(number1[2], date2, area1, strlen(date2));
      if(strval(number[0]) == strval(number1[0]) && strval(number[1]) == strval(number1[1]) && strval(number[2]) == strval(number1[2]))
      {
          return 1;
      }
      else
      {
          return 0;
      }
   }
}
I make new number 80 bytes that means my date1 or date2 have to by smaller than 80 bytes?
No, make them 80 byte too.