How to filter a value?
#2

You only need to split the string

pawn Code:
new day, month, year = -1 = month = day;
for(new c = 0/* Startpoint */, s = c; text[c] != EOS; c++) //the text should start at the date
    if(text[c] == '/')
    {
        if(day == -1)
        {
            if((c - s) > 2) break;
            for(day = 0; s < c; s++)
                day = day * 10 + (text - '0');
            s++;
        }
        else if(month == -1)
        {
            if((c - s) > 2) break;
            for(month = 0; s < c; s++)
                month = month * 10 + (text - '0');
            s++;
        }
    }
    else if(text[c] == ' ')
    {
        if(month == -1 || day == -1) break;
        else if((c - s) > 4) break;
        for(year = 0; s < c; s++)
            year = year * 10 + (text - '0');
        break;
    }
    else if(!('0' <= text[c] <= '9')) break;
if(year == -1 || month == -1 || day == -1) return 0;
if you use it
at OnPlayerText
pawn Code:
if(PlayerTypesDate[playerid])
{
    if(!('0' <= text[0] <= '9')) return SendClientMessage(playerid, 0xFFFFFFAA, "Enter the date in the format dd/mm/yyyy");
    //code above - c = 0
}
at OnPlayerCommandText
pawn Code:
if(strcmp("/command", cmdtext, true, 8 /* strlen("/command") */) == 0)
{
    if(cmdtext[8/* strlen("/command") */] != ' ' || cmdtext[9/* strlen("/command") + 1 */] == EOS)
        return SendClientMessage(playerid, 0xFFFFFFAA, "Enter the date in the format dd/mm/yyyy");
    //code above - c = 9 /* strlen("/command") + 1 */
}
Reply


Messages In This Thread
How to filter a value? - by x-cutter - 02.01.2010, 21:47
Re: How to filter a value? - by Nero_3D - 02.01.2010, 23:33
Re: How to filter a value? - by x-cutter - 02.01.2010, 23:56
Re: How to filter a value? - by Nero_3D - 03.01.2010, 00:07
Re: How to filter a value? - by x-cutter - 03.01.2010, 00:28
Re: How to filter a value? - by x-cutter - 03.01.2010, 00:45
Re: How to filter a value? - by Nero_3D - 03.01.2010, 01:35

Forum Jump:


Users browsing this thread: 2 Guest(s)