Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact
/*******************************************************************************

        Split text on a matched pattern

*******************************************************************************/

import tango.io.Console;
import Text = tango.text.Util;

void main()
{
        string source = "all cows eat grass";

        // split into an array
        string[] elements = Text.split (source, "eat");
        foreach (element; elements)
                 Cout(element).newline;

        // incremental alternative with no heap activity
        foreach (element; Text.patterns (source, "eat"))
                 Cout(element).newline;
}