Wiki source for KeyPgOpStringIndex

Show raw source

{{fbdoc item="title" value="Operator [] (String index)"}}----
Returns a reference to a character in a string

{{fbdoc item="syntax"}}##
[[KeyPgDeclare|declare]] [[KeyPgOperator|operator]] **[]** ( [[KeyPgByref|byref]] //lhs// [[KeyPgAs|as]] [[KeyPgString|string]], [[KeyPgByref|byref]] //rhs// [[KeyPgAs|as]] [[KeyPgInteger|integer]] ) [[KeyPgByrefFunction|byref]] [[KeyPgAs|as]] [[KeyPgUbyte|ubyte]]
[[KeyPgDeclare|declare]] [[KeyPgOperator|operator]] **[]** ( [[KeyPgByref|byref]] //lhs// [[KeyPgAs|as]] [[KeyPgZstring|zstring]], [[KeyPgByref|byref]] //rhs// [[KeyPgAs|as]] [[KeyPgInteger|integer]] ) [[KeyPgByrefFunction|byref]] [[KeyPgAs|as]] [[KeyPgUbyte|ubyte]]
[[KeyPgDeclare|declare]] [[KeyPgOperator|operator]] **[]** ( [[KeyPgByref|byref]] //lhs// [[KeyPgAs|as]] [[KeyPgWstring|wstring]], [[KeyPgByref|byref]] //rhs// [[KeyPgAs|as]] [[KeyPgInteger|integer]] ) [[KeyPgByrefFunction|byref]] [[KeyPgAs|as]] //T//
{{fbdoc item="usage"}}##
//result// = //lhs// **[** //rhs// **]**
{{fbdoc item="param"}}
The string (a string reference, not a string returned as local copy).
A zero-based offset from the first character.
The wide-character type (varies per platform).

{{fbdoc item="desc"}}
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, ##[[KeyPgLen|Len]](//lhs//) - 1##]". Outside this range, results are undefined.

{{fbdoc item="ex"}}
{{fbdoc item="filename" value="examples/manual/operator/stringindex.bas"}}%%(freebasic)
dim a as string = "Hello, world!"
dim i as integer

for i = 0 to len(a) - 1
print chr(a[i]) & " ";
next i

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

{{fbdoc item="diff"}}
- New to ""FreeBASIC""

{{fbdoc item="see"}}
- [[CatPgOpString|String Operators]]

{{fbdoc item="back" value="CatPgOpIndexing|Indexing Operators"}}{{fbdoc item="back" value="CatPgOperators|Operators"}}
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki phatcode