3.5.7.40 TokenToken-func
Description
Get the iToken-th token from a string str$ using specified delimiter iDelimiter.
Syntax
string Token(string str$, int iToken [, int iDelimiter])$
Parameters
str
- The string from which you want to get token.
iToken
- Specifies the token index (from 1). 0 = the last token, -1 = the second-to-last token.
iDelimiter
- Indicates the ASCII value of the delimiter. The default 0 denotes any white space characters. 32 means single space and 124 means '|'. You can also directly use char type such as "_" (ASCII 95), "|"(ASCII 124) as the value of iDelimiter which is equivalent to its corresponding ASCII value.
Note: some symbol chars might not be directly used by iDelimiter but their ASCII values always apply.
Return
returns Nth token in the string.
Example
Token("This is my string", 0)$=; //should return "string"
str1$="This is my string";
str2$=Token(str1$,3)$;
str3$=Token(str1$,-1)$;
//should both be "my"
str2$=;
str3$=;
str1$="This\is\my\string";
str2$=Token(str1$, 2, "\")$;
str2$=;//should be "is"
str1$="This#is#my#string";
int ascval = code("#"); //ascval is 35
str2$=Token(str1$, 4, $(ascval))$;
str2$=;//should be "string"
str1$ = " aa bb";
str2$ = Token(str1$,1,32);
str2$ = ; //should return "aa" since the beginning white space is trimmed
See Also
Mid
|