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

        Incremental replacement of text elements

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

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

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

        // replace "eat" with "chew"
        char[] replaced = Text.substitute (source, "eat", "chew");
        Cout(replaced).newline;

        // incrementally replace "eat" with "chew", sans heap activity
        foreach (element; Text.patterns (source, "eat", "chew"))
                 Cout(element);
        Cout.newline;
}