strcmp date
#1

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

Split with sscanf. Or use a regular expression.
Reply
#3

Can give example?
Reply
#4

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

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;
      }
   }

Reply
#6

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

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

Can i use 2 sscanf in one command?
Reply
#9

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

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

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

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

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?
Reply
#13

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


Forum Jump:


Users browsing this thread: 1 Guest(s)