CopyPastehas never been so tasty!

Format String using String.Format method in

by anonymous

  • 0
  • 0
  • 0

Orignal Source:


String.Format Function:


String.Format is a static method and by using String.Format method you can change the format of different data types into string for example you can change the format of numerical or Boolean values into string. String.Format takes a format string and argument will return a string. Formatting strings are useful.


The syntax of Format string is


string string.format(string format,Object arg0)


It takes an argument and format string as parameter.



Format String using String.Format method:


To understand that how we can use the String.Format method let us consider this example declare a float type number and pass it to the String.Format method with an argument.


To demonstrate make a console application and write the following code.







staticvoid Main(string[] args)


floatmyFloat = 1234.56789f;

string myString8 = String.Format("{0, 10:f3}", myFloat);

Console.WriteLine("String.Format(\"{0, 10:f3}\", myFloat) = " + myString8);







Add A Comment: