$gettok

From Scriptwiki
Revision as of 14:52, 18 December 2005 by Albie (talk | contribs)

Jump to: navigation, search

Returns the Nth token or amount of tokens in string.

$gettok(string,N,C)

Where N is the Nth token you wish to be returned from string by delimiter C. Alternatively N can be given as 0 to return the amount of tokens in string

Examples

$gettok(Ave:IT,1,58)  ;returns Ave

This returns the first token using $chr(58) as the delimiter

$gettok(Ave:IT,0,58)  ;returns 2

This returns the value 2 because there is two values when delimited by $chr(58)

Note: N can be a range N1-N2, Example:

$gettok(Word1 Word2 Word3 Word4,2-3,32)   ;returns Word2 Word3 From word 2 until word 3.
$gettok(Word1 Word2 Word3 Word4,3-,32)    ;returns Word3 Word4 From the third word until the end.
$gettok(Word1 Word2 Word3 Word4,-2-,32)   ;returns Word3 Word4 From the second-to-last word, until the end.
$gettok(Word1 Word2 Word3 Word4,-3--2,32) ;returns Word2 Word3 From the third-to-last word, until the second-to-last word.

Note: Although it may seam resonable to use -3-4 in this situation to get the third-to-last word (Word2) until the forth word (Word4), $gettok() does not calulate it this way, you will end up with the same as -3-.