16.08.2015, 16:09
Код:
// 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 ...