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

Appending

Part of TutorialFundamentals

Description

Shows how appending works with D dynamic strings.

Example

import std.stdio;

void main() {
    string s;
    writefln("Length: %d\tString: '%s'", s.length, s);

    s ~= "something ";
    writefln("Length: %d\tString: '%s'", s.length, s);

    s ~= "whatever";
    writefln("Length: %d\tString: '%s'", s.length, s);
}

Output

Length: 0       String: ''
Length: 10      String: 'something '
Length: 18      String: 'something whatever'

Source

Based on appending.html by jcc7.