Better string mixins

JN 666total at wp.pl
Fri Dec 28 13:07:27 UTC 2018


On Friday, 28 December 2018 at 12:51:33 UTC, SashaGreat wrote:
>
> By the way, thinking more about it, in C# (My main language), 
> in could easily create a extension for this like:
>
> public static Format(string this, object[] args){
>     // Loop through all the {x} replacing with arg[x]
> }
>
> Then
>
> "x = {0}".Format(1);
>
> "x = {0}; y = {0}".Format(10, 20);
>
> Is this possible with D?
>
> S.

In D, UFCS does what C# extension methods do. If you have a 
function foo that takes a string argument first, you can either 
call it as foo(s, somethingsomething) or 
s.foo(somethingsomething).


More information about the Digitalmars-d mailing list