Revision [15010]
This is an old revision of KeyPgOpStringIndex made by FxMwikki on 2010-12-18 06:52:26.
Operator [] (String index)
Returns a reference to a character in a string
Syntax:
KeyPgDeclare declare KeyPgOperator operator [] ( KeyPgByref byref lhs KeyPgAs as KeyPgString string, KeyPgByref byref rhs KeyPgAs as KeyPgInteger integer ) KeyPgAs as KeyPgUbyte ubyte
KeyPgDeclare declare KeyPgOperator operator [] ( KeyPgByref byref lhs KeyPgAs as KeyPgZstring zstring, KeyPgByref byref rhs KeyPgAs as KeyPgInteger integer ) KeyPgAs as KeyPgUbyte ubyte
KeyPgDeclare declare KeyPgOperator operator [] ( KeyPgByref byref lhs KeyPgAs as KeyPgWstring wstring, KeyPgByref byref rhs KeyPgAs as KeyPgInteger integer ) KeyPgAs as T
KeyPgDeclare declare KeyPgOperator operator [] ( KeyPgByref byref lhs KeyPgAs as KeyPgZstring zstring, KeyPgByref byref rhs KeyPgAs as KeyPgInteger integer ) KeyPgAs as KeyPgUbyte ubyte
KeyPgDeclare declare KeyPgOperator operator [] ( KeyPgByref byref lhs KeyPgAs as KeyPgWstring wstring, KeyPgByref byref rhs KeyPgAs as KeyPgInteger integer ) KeyPgAs as T
- Note that Operator {} (String index) returns a reference. See [CompilerFAQ Compiler FAQ]].
Usage:
result = lhs [ rhs ]
Parameters:
lhs
The string.
rhs
A zero-based offset from the first character.
T
The wide-character type (varies per platform).
Description:
This operator returns a reference to a specific character in a string:
- This operator must not be used in case of an empty string because reference is undefined (inducing runtime error).
- Otherwise, the user must ensure that the index does not exceed the range "[0, KeyPgLen Len(lhs) - 1]". Outside this range, results are undefined.
Examples:
Dim a As String = "Hello, world!"
Dim i As Integer
For i = 0 To Len(a) - 1
Print Chr(a[i]);
Next i
Print
Dim i As Integer
For i = 0 To Len(a) - 1
Print Chr(a[i]);
Next i
Will print
Hello, world!
Differences from QB:
- New to FreeBASIC
See also:
Back to Indexing Operators
Back to Operators