Skip to content

Instantly share code, notes, and snippets.

@nathan130200
Created August 31, 2018 15:28
Show Gist options
  • Save nathan130200/ac0f77370bb5da0118d0e15415239c1c to your computer and use it in GitHub Desktop.
Save nathan130200/ac0f77370bb5da0118d0e15415239c1c to your computer and use it in GitHub Desktop.
C# printf function
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