Named format string extension method - instead of string.Format("{0} first, {1} second", 3.14, DateTime.Now) the following can be used:
string.Format("{pi} first, {date} second", someObj)
Formats such as {foo.bar.baz} where baz is a property of bar which is a property of foo are also allowed.
Namespace: MonoSoftware.CoreAssembly: MonoSoftware.Core (in MonoSoftware.Core.dll) Version: 1.0.40.669 (1.0.40.669)
Syntax
C# |
---|
public static string FormatWith( this string format, IFormatProvider provider, Object source, string value, bool useRegexReplace ) |
Visual Basic |
---|
<ExtensionAttribute> Public Shared Function FormatWith ( format As String, provider As IFormatProvider, source As Object, value As String, useRegexReplace As Boolean ) As String |
Visual C++ |
---|
public: [ExtensionAttribute] static String^ FormatWith( String^ format, IFormatProvider^ provider, Object^ source, String^ value, bool useRegexReplace ) |
F# |
---|
static member FormatWith : format : string * provider : IFormatProvider * source : Object * value : string * useRegexReplace : bool -> string |
Parameters
- format
- Type: System..::..String
Format string.
- provider
- Type: System..::..IFormatProvider
Format provider.
- source
- Type: System..::..Object
Object to format.
- value
- Type: System..::..String
Named format string value
- useRegexReplace
- Type: System..::..Boolean
Use regular expression replace
Return Value
Type: StringFormatted string.
Usage Note
In Visual Basic and C#, you can call this method as an instance method on any object of type String. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).Remarks
For further reference, check http://haacked.com/archive/2009/01/04/fun-with-named-formats-string-parsing-and-edge-cases.aspx;