469,600 Members | 2,453 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,600 developers. It's quick & easy.

Format method of String Type

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
Nov 20 '05 #1
4 1453
{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" <Da**********@compusa.com> wrote in message
news:75**********************************@microsof t.com...
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

Nov 20 '05 #2
Thank you very much for the quick & clear explanation!
Nov 20 '05 #3
David,
In addition to Adian's comments. The formatting allowed is explained here:

http://msdn.microsoft.com/library/de...ngoverview.asp

Specifically:

http://msdn.microsoft.com/library/de...formatting.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" <Da**********@compusa.com> wrote in message
news:75**********************************@microsof t.com...
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

Nov 20 '05 #4
"David Morris" <Da**********@compusa.com> schrieb
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

Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Chris Stiles | last post: by
6 posts views Thread by WindAndWaves | last post: by
7 posts views Thread by tolisss | last post: by
9 posts views Thread by Alok yadav | last post: by
8 posts views Thread by Lucky | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.