Created
August 31, 2018 15:28
-
-
Save nathan130200/ac0f77370bb5da0118d0e15415239c1c to your computer and use it in GitHub Desktop.
C# printf function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static string PrintF(params object[] a) | |
{ | |
if (a == null || a.Length == 0) return string.Empty; | |
int[] i = { 1 }; | |
string s = (a[0] is string) ? System.Text.RegularExpressions.Regex.Replace((string)a[0], "%[sdi%]", | |
match => match.Value == "%%" ? "%" : i[0] < a.Length ? a[i[0]++].ToString() : match.Value) : a[0].ToString(); | |
for (; i[0] < a.Length; i[0]++) | |
s += " " + a[i[0]]; | |
return s; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment