Operator [] (String Index)

FreeBASIC

Operator [] (String Index)
 
Returns a reference to a character in a string

Syntax
Usage

result = lhs [ rhs ]

Parameters

lhs
The string (a string reference, not a string returned as local copy).
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 empty string because reference is undefined (inducing runtime error).
    • Otherwise, the user must ensure that the index does not exceed the range "[0, Len(lhs) - 1]". Outside this range, results are undefined.

Example

Dim a As String = "Hello, world!"
Dim i As Integer

For i = 0 To Len(a) - 1
    Print Chr(a[i]) & " ";
Next i
Print


Will print
H e l l o ,   w o r l d ! 

Differences from QB

  • New to FreeBASIC

See also