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

Foreach with a string literal

Part of ForeachCategory


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


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


Tested with DMD 0.169 on Windows 2000.