Difference between revisions of "$gettok"

From Scriptwiki
Jump to: navigation, search
(Adding example for negative ranges)
m (fixed commenting syntax and some minor tweak)
Line 3: Line 3:
 
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 ''string'' by delimiter ''C''. Alternatively ''N'' can be given as 0 to return the amount of tokens in ''string''
  
== Example ==
+
== 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
  
  $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 is two values when delimited by $chr(58)
  
'''Note:''' ''N'' can be a range N1-N2, Example:
+
'''Note:''' ''N'' can be a range N1-N2, Example:
  $gettok(Word1 Word2 Word3 Word4,2-3,32) returns ''Word2 Word3''
+
  $gettok(Word1 Word2 Word3 Word4,2-3,32) ;returns ''Word2 Word3''
  $gettok(Word1 Word2 Word3 Word4,-2-1,32) returns ''Word3 Word4''
+
  $gettok(Word1 Word2 Word3 Word4,-2-1,32) ;returns ''Word3 Word4''
 
The second example would return the second token from the end until one token from the end.
 
The second example would return the second token from the end until one token from the end.
 
[[Category:Token Identifiers]]
 
[[Category:Token Identifiers]]

Revision as of 15:46, 10 November 2005

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
$gettok(Word1 Word2 Word3 Word4,-2-1,32)  ;returns Word3 Word4

The second example would return the second token from the end until one token from the end.