1 module polyplex.utils.strutils; 2 import std.conv; 3 import std.array; 4 import std.stdio; 5 import core.vararg; 6 7 /** 8 C# style text formatting. 9 Add {(id)} in text to specify replacement points, specified arguments (after sequential id) will replace the text with a to!string variant. 10 */ 11 public static string Format(T...)(string format, T args) { 12 string result = format; 13 static foreach(i; 0 .. args.length) { 14 result = result.replace("{" ~ i.text ~ "}", args[i].text); 15 } 16 return result; 17 } 18 19 /* 20 public static string Format(string message, ...) { 21 string[] formatstr; 22 for (int i = 0; i < _arguments.length; i++) { 23 formatstr ~= va_arg!string(_argptr); 24 } 25 return FormatStr(message, formatstr); 26 } 27 28 public static string FormatStr(string base, string[] format) { 29 string o = base; 30 for(int i = 0; i < format.length; i++) { 31 o = replace(o, "{"~to!string(i)~"}", format[i]); 32 } 33 return o; 34 }*/