Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
Previous Versions
.NET Framework 2.0
System
String Class
String Methods
Format Method

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
.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.

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.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
New Subject      Scott Swigart - MVP   |   Edit   |   Show History

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

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

Tags What's this?: Add a tag
Flag as ContentBug
Beware of performance cost      AlexanderJ ... Guenter   |   Edit   |   Show History

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 What's this?: Add a tag
Flag as ContentBug
Formatting Strings in C#      Reman   |   Edit   |   Show History

A nice overview about formatting strings in c#

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

Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker