$gettok
From Scriptwiki
Revision as of 03:16, 3 February 2006 by Microbe (talk | contribs) (tweaking. someone also complete $chr)
Returns the Nth token or amount of tokens in a string.
$gettok(string,N,C)
Where N is the Nth token you wish to be returned from the string by delimiter C. Alternatively N can be given as 0 to return the amount of tokens in the string.
For more information about the delimiters, see $chr.
Examples
$gettok(Ave:IT,1,58) ;returns Ave
This returns the first token using $chr(58) as the delimiter, which is character :
$gettok(Ave:IT,0,58) ;returns 2
This returns the value 2 because there are two values delimited by a $chr(58)
Note: N can be a range N1-N2. Examples where the delimiter is $chr(32) (a space):
$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 calculate it this way, you will end up with the same as -3-.