D version of C# code

Joel via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Apr 16 19:51:32 PDT 2017


On Sunday, 16 April 2017 at 09:46:13 UTC, ag0aep6g wrote:
> On 04/16/2017 11:20 AM, Joel wrote:
>> [...]
>
> void main()
> {
>     // Arrange
>     const string templateString = "My {pet} has {number} 
> {ailment}.";
>     auto pairs = [
>         "pet": "dog",
>         "number": "5",
>         "ailment": "fleas",
>     ];
>
>     // Act
>     import std.regex: regex, replaceAll;
>     auto result = templateString
>         .replaceAll!(m => pairs[m[1]])(regex(`\{([^}]+)\}`));
>
>     // Assert
>     assert(result == "My dog has 5 fleas.");
> }

Thanks, ag0aep6g.


More information about the Digitalmars-d-learn mailing list