Changes

Jump to: navigation, search

Formatting Strings in C Sharp

1,107 bytes added, 15:34, 24 January 2008
New page: In addition to the wide selection of string manipulation functions outlined in Working with Strings in C#, the string class also provides the ''String.F...
In addition to the wide selection of string manipulation functions outlined in [[Working with Strings in C Sharp|Working with Strings in C#]], the string class also provides the ''String.Format()'' method.

The primary purpose of the C# ''String.Format()'' method is to provide a mechanism for inserting string, numerical or boolean values into a string.

== The Syntax of the String.Format() Method ==

The general syntax of the String.Format() method is as follows:

String.Format(''format string", ''arg1'', ''arg2'', .... );

The ''format string'' is the string into which the values will be placed. Within this string are ''place holders'' which indicate the location of each value within the string. Place holders take the form of braces surrounding a number indicating argument to be substituted for the place holder. Following on from the ''format string'' is a comma separated list of arguments. There must be an argument for each of the place holders.

== A Simple C# String Format Example ==

The following code fragment demonstrates a very simple use of the String.Format() method:

<pre>
</pre>

Navigation menu