String.opIndex

  1. inout(char) opIndex(size_t pos)
  2. ByCodeUnit!char opIndex()
    struct String
    @nogc nothrow pure @trusted
    opIndex
    ()
  3. ByCodeUnit!(const char) opIndex()

Return Value

Type: ByCodeUnit!char

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

Examples

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);
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');

Meta