PeekPreviousChar (StringTokenizer function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
mNo edit summary
Line 32: Line 32:
%tok:string = 'Example of peekPreviousChar'
%tok:string = 'Example of peekPreviousChar'


PrintText {~} is {%tok:nextToken}
[[Targeted Text statements#AuditText, PrintText, and TraceText|PrintText]] {~} is {%tok:nextToken}
PrintText {~} is {%tok:previousChar}
PrintText {~} is {%tok:previousChar}
PrintText {~} is {%tok:previousChar}
PrintText {~} is {%tok:previousChar}

Revision as of 20:33, 15 November 2012

Value of previous character (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. The tokenizing position is the value returned by NextPosition.

PeekPreviousChar does not change the tokenizing position.

Syntax

%string = stringTokenizer:PeekPreviousChar

Syntax terms

%string A string variable to receive the value of the character that precedes the character at the tokenizing position.
stringTokenizer A StringTokenizer object expression.

Usage notes

  • If you are not using separators, PeekPreviousChar always returns the last character of the last returned token.
  • The PreviousChar function also returns the value of the character that precedes the character that is at the tokenizing position, but it steps the tokenizing position back to the preceding character.

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 peekPreviousChar' PrintText {~} is {%tok:nextToken} PrintText {~} is {%tok:previousChar} PrintText {~} is {%tok:previousChar} PrintText {~} is {%tok:peekPreviousChar} PrintText {~} is {%tok:peekPreviousChar}

The result is:

{%tok:nextToken} is Example {%tok:previousChar} is e {%tok:previousChar} is l {%tok:peekPreviousChar} is p {%tok:peekPreviousChar} is p

See also