get day month and year from string - 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: get day month and year from string (
/showthread.php?tid=585775)
get day month and year from string -
dud - 16.08.2015
i have string
04.06.2015
i want to get day month and year from this string (04.06.2015 ) and store it to variables like
day = 04
month = 06
year = 2015
any help
Re: get day month and year from string -
prineside - 16.08.2015
Код:
// Useful function to split a string by symbol
// Usage:
// new destination[3][16];
// split( "my.source.string", destination, '.', 3 );
// Now destination is:
// [0] => "my"
// [1] => "source"
// [2] => "string"
stock split(const strsrc[], const strdest[][], delimiter, destlen)
{
new i, li;
new aNum;
new len;
while(i <= strlen(strsrc))
{
if(strsrc[i] == delimiter || i == strlen(strsrc))
{
len = strmid(strdest[aNum], strsrc, li, i, 128);
strdest[aNum][len] = 0;
li = i+1;
aNum++;
}
i++;
}
if (aNum < destlen) {
for (new j=aNum; j < destlen; j++) {
strdest[j][0] = 0;
}
}
return 1;
}
stock stringToDate( const dateAsString[], &day, &month, &year ) {
new dest[3][5];
split( dateAsString, dest, 3 );
day = strval( dest[0] );
month = strval( dest[1] );
year = strval( dest[2] );
}
// How to use:
...
new day, month, year;
stringToDate( "11.06.2015", day, month, year );
// now day == 11, month == 6, year == 2015
...
Re: get day month and year from string -
Vince - 16.08.2015
Or simply use sscanf:
pawn Код:
sscanf(datestr, "p<.>ddd", day, month, year);
Re: get day month and year from string -
dud - 17.08.2015
Thanks @prineside & @Vince
Solved