Difference between revisions of "$gettok"

From Scriptwiki
Jump to: navigation, search
(tweaking. someone also complete $chr)
Line 1: Line 1:
Returns the Nth token or amount of tokens in ''string''.
+
Returns the Nth token or amount of tokens in a ''string''.
 
  $gettok(''string'',''N'',''C'')
 
  $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''
+
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 ==
 
== Examples ==
 
  $gettok(Ave:IT,1,58)  ;returns ''Ave''
 
  $gettok(Ave:IT,1,58)  ;returns ''Ave''
This returns the first token using [[$chr]](58) as the delimiter
+
This returns the first token using $chr(58) as the delimiter, which is character :
  
 
  $gettok(Ave:IT,0,58)  ;returns ''2''
 
  $gettok(Ave:IT,0,58)  ;returns ''2''
This returns the value ''2'' because there is two values when delimited by $chr(58)
+
This returns the value ''2'' because there are two values delimited by a $chr(58)
  
'''Note:''' ''N'' can be a range N1-N2, Example:
+
'''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,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,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,-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.
 
  $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-.
+
'''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-.
 +
 
 
[[Category:Token Identifiers]]
 
[[Category:Token Identifiers]]

Revision as of 04:16, 3 February 2006

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-.