Changes

Jump to: navigation, search

Formatting Strings in C Sharp

641 bytes added, 15:46, 24 January 2008
A Simple C# String Format Example
<pre>
string newString;
 
newString = String.Format("There are {0} cats in my {1} and no {2}", 2, "house", "dogs");
 
System.Console.WriteLine (newString);
</pre>
 
When run, the above code will result in the following output:
 
<pre>
There are 2 cats in my house and no dogs
</pre>
 
Let's quickly review the String.Format() method call. The ''format string'' contains 3 place holder indicated by {0}, {1} and {2}. Following the format string are the arguments to be used in each place holder. For example, {0} is replaced by the first argument (the number 2), the {1} by the second argument (the string "house) and so on.
 
== Using Format Controls ==

Navigation menu