January 02, 2020 Re: Concatenation/joining strings together in a more readable way | ||||
---|---|---|---|---|
| ||||
Posted in reply to BoQsc | On Wednesday, 25 December 2019 at 12:39:08 UTC, BoQsc wrote: > Are there any other ways to join two strings without Tilde ~ character? > I can't seems to find anything about Tilde character concatenation easily, nor the alternatives to it. Can someone share some knowledge on this or at least point out useful links/resources? Fixed last bug, now is working fine: import std; import std: Format = format; // Function format() text = text.Replace("%", "%%"); string format(T...)(string text, T args){ foreach(n, i; args){ text = text.replace("{%d}".Format(n+1), "%s$s".Format("%" ~ to!string(n+1))); } return text.replace("{}", "%s").Format(args); } void main(){ writeln("Hi {} how are you {}?".format("Marcone", "today")); // Hi Marcone how are you today? writeln("My name is {2} and I live in {1}.".format("Brazil", "Marcone")); // My name is Marcone and I live in Brazil. writeln("We are {2} and {1}. I am {} and you {}. ".format("Marcone", "Paul")); // We are Paul and Marcone. I am Marcone and you Marcone. } |
January 02, 2020 Re: Concatenation/joining strings together in a more readable way | ||||
---|---|---|---|---|
| ||||
Posted in reply to BoQsc | On Wednesday, 25 December 2019 at 12:39:08 UTC, BoQsc wrote: > Are there any other ways to join two strings without Tilde ~ character? > I can't seems to find anything about Tilde character concatenation easily, nor the alternatives to it. Can someone share some knowledge on this or at least point out useful links/resources? There is a string interpolation DIP in progress. Doesn't help you now, but a future reader might find this thread. https://github.com/dlang/DIPs/blob/master/DIPs/DIP1027.md |
Copyright © 1999-2021 by the D Language Foundation