Replace

Performs compile time string replacements on base

Parameters:

T = replacement specs, alternating between string to be replaced and toStringNow-able object to replace with.

template Replace (
string base
T...
) {
enum Replace;
enum Replace;
}

Examples

1 import std.stdio;
2 
3 void main()
4 {
5   string s = Replace!(q{$ret func(T)(T t){ return new $ret(t+$i); }},
6     "$ret", "C",
7     "$i", 5000);
8   writeln(s); // "C func(T)(T t){ return new C(t+5000); }"
9 }

If there is ambiguity between two substrings to replace, the longer one is preferred:

enum s = Replace!("boy eats boysenberry", "boy", "girl", "boysenberry", "plum");
writeln(s) // "girl eats plum"

Meta