String Formatting
Snippets below have been condensed from their original sources for brevity. See references for original articles.
All examples are in C# .Net.
My own little function:
private string DynamicFormat(string dbformatstring, string contentstring) { foreach (string item in dbformatstring.Split(',')) { string propname = item.Split(':')[0]; string propvalue = item.Split(':')[1]; contentstring = contentstring.Replace("{"+propname+"}",propvalue); } return contentstring; }
Format With extension method by James Newton-King:
public static string FormatWith(this string format, params object[] args) { if (format == null) throw new ArgumentNullException("format"); return string.Format(format, args); } public static string FormatWith(this string format, IFormatProvider provider, params object[] args) { if (format == null) throw new ArgumentNullException("format"); return string.Format(provider, format, args); }
References
James Newton-King, “FormatWith”,http://james.newtonking.com/archive/2008/03/27/formatwith-string-format-extension-method.aspx
Posted on February 1, 2011, in Programming & Development and tagged .net develop, .net development, .net program, .net programming, .net string formatting, c# string formatting, csharp string formatting, format, net developer, net developing, program, programming, string format csharp, string format with name, string formatting, string.format. Bookmark the permalink. Leave a comment.
Leave a comment
Comments 0