Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Foreach with a string literal

Part of ForeachCategory

Description

Foreach aggregates can be string literals, which can be accessed as char, wchar, or dchar arrays.

Example

import std.stdio : writefln;

void main () {
    writefln("As a char...");
    foreach (char c; "abcdef")
        writefln("\t%s", c);

    writefln("As a wchar...");
    foreach (wchar w; "abcdef")
        writefln("\t%s", w);
}

Version

Tested with DMD 0.169 on Windows 2000.