StringUpTo (StringTokenizer function)
String from start to current position (StringTokenizer class)
[Introduced in Sirius Mods 7.8]
This method returns a substring of the tokenizing string, starting at the current position and ending just before the occurrence of its argument string.
Syntax
%string = stringTokenizer:StringUpTo( string)
Syntax terms
%string | A string variable to contain the returned substring. |
---|---|
stringTokenizer | A StringTokenizer object expression. |
string | The string within stringTokenizer up to which the tokenizer scans to determine the substring to return to %string.
If string is not found, StringUpTo returns the rest of the string being tokenized. |
Usage notes
- If StringUpTo locates an occurrence of its argument string, it advances the tokenizing position to the end of that located argument string.
- Because a failure to match the target string returns the rest of the tokenizer string, StringUpTo leaves no easy way to determine if you get a result string because you got a match or because you went to the end of the string. A good technique then may be to follow a StringUpTo call with a NextPosition call to check your result.
Examples
Here are two simple StringUpTo calls, the second of which does not locate its argument string:
b %tk is object stringTokenizer %ls is longstring %tk = new %tk:string = 'a b c --> d e' %ls = %tk:stringUpTo('-->') printtext {~} = {%ls} printtext {~} = {%tk:nextPosition} %ls = %tk:stringUpTo('---') printtext {~} = {%ls} printtext {~} = {%tk:nextPosition} end
The result is:
%ls = a b c %tk:nextPosition = 7 %ls = --> d e %tk:nextPosition = 14