473,383 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

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 1617
{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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Chris Stiles | last post by:
Is there a human readable dump format for objects ? As opposed to pickling ? It doesn't necessarily have to be XML - in fact i'd prefer if it wasn't ;) - but ISTR an XML dump library. --...
10
by: Jack | last post by:
Hi, I cannot get the date format correctly in dynamic sql statement, after trying various ways of handling it. I need some help with the date format in the following dynamic sql statement. Any...
6
by: WindAndWaves | last post by:
Hi Gurus In my quest in putting my first javascript together, I am now trying to conquer something that seems trivial, but has taken me hours. I would like to format a field in a form once the...
3
by: marwa mohamed | last post by:
salamo alikom hi all when i run report that includes image control linked to a field in the table that contains the image path(on the server)and the record source of the report contains over 30...
1
by: John Chorlton | last post by:
I've been attempting to pass a chunk of data back from a child Windows form using public properties on the form and have been getting some odd errors. I wanted to return a row of data to avoid...
7
by: tolisss | last post by:
Hi i have a string like "22/5/2006 12:00:00 pµ" and i want to create a string like "05/22/06" could someone please
4
by: Fresh_Air_Rider | last post by:
Hi In the "good old" Classic ASP days, I used to stream records from a SQL Server database out to the user's browser in CSV format by using a combination of COALESCE and the ADODB.Stream object....
9
by: Alok yadav | last post by:
i am using a webservice in which a method is serach. i use this method which accept a argument of date type in dd/MM/yyyy formate. i have a textbox which accept the date from the user, when i...
8
by: Lucky | last post by:
hi guys! back again with another query. the problem is like this. i want to print a line like this: "---------------------------------------------" the easiest way is to simply assign it to...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.