String.opIndex - multiple declarations

Function String.opIndex

ref inout inout(char) opIndex (
  const(ulong) pos
) pure nothrow @nogc @trusted;

Parameters

NameDescription
pos Position.

Returns

Byte at pos.

Precondition

length > pos.

Example

auto s = String("Alea iacta est.");
assert(s[0] == 'A');
assert(s[4] == ' ');

Function String.opIndex

ByCodeUnit!(char) opIndex() pure nothrow @nogc @trusted;

ByCodeUnit!(const(char)) opIndex() pure nothrow @nogc @trusted const;

Returns

Random access range that iterates over the string by bytes, in forward order.

Example

auto s = String("Plutarchus");
auto r = s[];
assert(r.front == 'P');
assert(r.back == 's');

r.popFront();
assert(r.front == 'l');
assert(r.back == 's');

r.popBack();
assert(r.front == 'l');
assert(r.back == 'u');

assert(r.length == 8);

Example

auto s = const String("Was ich vermag, soll gern geschehen. Goethe");
auto r1 = s[];
assert(r1.front == 'W');

auto r2 = r1[];
r1.popFront();
assert(r1.front == 'a');
assert(r2.front == 'W');