PreviousChar (StringTokenizer function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
mNo edit summary
 
(2 intermediate revisions by the same user not shown)
Line 23: Line 23:


==Examples==
==Examples==
The following sequence of <var>PrintText</var> statements display,
The following sequence of <var>[[Targeted Text statements|PrintText]]</var> statements  
respectively, <code>Example</code>, <code>e</code>, <code>l</code>, <code>p</code>, and <code>p</code>,
show that the tokenizing position moves after <var>PreviousChar</var> completes
showing that the tokenizing position moves after <var>PreviousChar</var> completes
but not after <var>PeekPreviousChar</var> completes:
but not after <var>PeekPreviousChar</var> completes:
<p class="code">%tok:string = 'Example of peekPreviousChar'
<p class="code">%tok = new
%tok:string = 'Example of previousChar'
 
PrintText {~} is {%tok:nextToken}
PrintText {~} is {%tok:nextToken}
PrintText {~} is {%tok:nextPosition}
PrintText {~} is {%tok:previousChar}
PrintText {~} is {%tok:nextPosition}
PrintText {~} is {%tok:previousChar}
PrintText {~} is {%tok:previousChar}
PrintText {~} is {%tok:previousChar}
PrintText {~} is {%tok:nextPosition}  
PrintText {~} is {%tok:peekPreviousChar}
PrintText {~} is {%tok:peekPreviousChar}
PrintText {~} is {%tok:nextPosition}
PrintText {~} is {%tok:peekPreviousChar}
PrintText {~} is {%tok:peekPreviousChar}
</p>
</p>
The result is:
<p class="output">%tok:nextToken is Example
%tok:nextPosition is 8   
%tok:previousChar is e   
%tok:nextPosition is 7   
%tok:previousChar is l   
%tok:nextPosition is 6   
%tok:peekPreviousChar is p
%tok:nextPosition is 6   
%tok:peekPreviousChar is p  </p>


==See also==
==See also==
{{Template:StringTokenizer:PreviousChar footer}}
{{Template:StringTokenizer:PreviousChar footer}}

Latest revision as of 23:49, 5 July 2012

Value of previous character and step back one position (StringTokenizer class)

[Introduced in Sirius Mods 7.8]


This method returns the value of the character that precedes the character that is at the tokenizing position, and it steps the tokenizing position back to the preceding character. The tokenizing position is the value returned by NextPosition.

Syntax

%string = stringTokenizer:PreviousChar

Syntax terms

%string A string variable to receive the returned character value.
stringTokenizer A StringTokenizer object variable.

Usage notes

  • The PeekPreviousChar function also returns the value of the next character, but it does not step back the tokenizing position.

Examples

The following sequence of PrintText statements show that the tokenizing position moves after PreviousChar completes but not after PeekPreviousChar completes:

%tok = new %tok:string = 'Example of previousChar' PrintText {~} is {%tok:nextToken} PrintText {~} is {%tok:nextPosition} PrintText {~} is {%tok:previousChar} PrintText {~} is {%tok:nextPosition} PrintText {~} is {%tok:previousChar} PrintText {~} is {%tok:nextPosition} PrintText {~} is {%tok:peekPreviousChar} PrintText {~} is {%tok:nextPosition} PrintText {~} is {%tok:peekPreviousChar}

The result is:

%tok:nextToken is Example %tok:nextPosition is 8 %tok:previousChar is e %tok:nextPosition is 7 %tok:previousChar is l %tok:nextPosition is 6 %tok:peekPreviousChar is p %tok:nextPosition is 6 %tok:peekPreviousChar is p

See also