Format method of String Type

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

Could somebody please explain what the following line of code means

String.Format("{0}\{1}.{2:00}", C:\, myfile.txt, 1

It's actually the first argument that I don't understand. What is the purpose of "{0}\{1}.{2:00}"? I've been using VB .NET for a year now, and have never come across anything like this

Best Regards
David Morris
 
{0} is a placeholder for the first parameter "c:\". {1} is a placeholder
for the second and {2:00} is a placeholder for the third and the : means
there is format data following and 00 means the format for the param (two
digit number)

Result should be;

c:\\myfile.txt.01

Putting {} around the params for explanation

{c:\}\{myfile.txt}.{01}

David Morris said:
Hi,

Could somebody please explain what the following line of code means?

String.Format("{0}\{1}.{2:00}", C:\, myfile.txt, 1)

It's actually the first argument that I don't understand. What is the
purpose of "{0}\{1}.{2:00}"? I've been using VB .NET for a year now, and
have never come across anything like this?
 
David Morris said:
Hi,

Could somebody please explain what the following line of code
means?

String.Format("{0}\{1}.{2:00}", C:\, myfile.txt, 1)

It's actually the first argument that I don't understand. What is
the purpose of "{0}\{1}.{2:00}"? I've been using VB .NET for a year
now, and have never come across anything like this?

Have you come across the F1 key? ;-) The syntax of the 1st arg is described
in the docs.


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
David,
In addition to Adian's comments. The formatting allowed is explained here:

http://msdn.microsoft.com/library/d...n-us/cpguide/html/cpconformattingoverview.asp

Specifically:

http://msdn.microsoft.com/library/d...-us/cpguide/html/cpconcompositeformatting.asp

In addition to String.Format: Console.WriteLine & TextWriter.WriteLine also
support format specfiers. Also a number of controls in ASP.NET support a
format property that is used during data binding.

Using a format specifier is very useful for internationalization, as the
place holders in the format string do not need to be in consecutive order.


Const firstName As String = "{0} {1} {2}"
Const lastName As String = "{2}, {0} {1}"

Dim s As String
Dim format As String

format = firstName
s = String.Format(format, "Jay", "B.", "Harlow")

format = lastName
s = String.Format(format, "Jay", "B.", "Harlow")

Where the format (firstName or lastName) is supplied from outside the
routine (such as a resource file (.RESX)). Notice that the three parts of
the name are supplied in the same order to String.Format, however the format
string itself changed for each "format" we wanted to support...

Hope this helps
Jay

David Morris said:
Hi,

Could somebody please explain what the following line of code means?

String.Format("{0}\{1}.{2:00}", C:\, myfile.txt, 1)

It's actually the first argument that I don't understand. What is the
purpose of "{0}\{1}.{2:00}"? I've been using VB .NET for a year now, and
have never come across anything like this?
 
Back
Top