.NET Framework Class Library
String.Format Method

Replaces each format item in a specified String with the text equivalent of a corresponding object's value.

Overload List

Name Description
String.Format (String, Object) Replaces the format item in a specified String with the text equivalent of the value of a specified Object instance.

Supported by the .NET Compact Framework.

String.Format (String, Object[]) Replaces the format item in a specified String with the text equivalent of the value of a corresponding Object instance in a specified array.

Supported by the .NET Compact Framework.

String.Format (IFormatProvider, String, Object[]) Replaces the format item in a specified String with the text equivalent of the value of a corresponding Object instance in a specified array. A specified parameter supplies culture-specific formatting information.

Supported by the .NET Compact Framework.

String.Format (String, Object, Object) Replaces the format item in a specified String with the text equivalent of the value of two specified Object instances.

Supported by the .NET Compact Framework.

String.Format (String, Object, Object, Object) Replaces the format item in a specified String with the text equivalent of the value of three specified Object instances.

Supported by the .NET Compact Framework.

See Also

Tags :


Community Content

Scott M Swigart
New Subject

If you're interested in examples of format strings go here:

http://msdn2.microsoft.com/en-us/library/fbxft59x.aspx

Tags :

Guenter
Beware of performance cost

If you need string.Format, use it. However be aware that string.Format is quite expensive in terms of performance, therefore I recommend to

  • use string.Concat if feasible
  • use StringBuilder for more cases that don't need special formatting of values
  • If there are any conditions that might prevent the resulting string to be used, check those conditions before calling string.Format
    • Especially in the case of tracing (where string.Format ist used regularly) avoid calling string.Format unless you know that tracing is actually done (e.g. check the tace level before calling string.Format). This way you make sure that tracing will introduce minimal overhead when disabled.

 

Tags :

Reman
Formatting Strings in C#

A nice overview about formatting strings in c#

http://blog.stevex.net/index.php/string-formatting-in-csharp/

Tags : string

Page view tracker