473,545 Members | 1,989 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1625
{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.t xt}.{01}

"David Morris" <Da**********@c ompusa.com> wrote in message
news:75******** *************** ***********@mic rosoft.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.WriteLi ne & TextWriter.Writ eLine 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 internationaliz ation, 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(f ormat, "Jay", "B.", "Harlow")

format = lastName
s = String.Format(f ormat, "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**********@c ompusa.com> wrote in message
news:75******** *************** ***********@mic rosoft.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**********@c ompusa.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
2397
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. -- regards, chris
10
1864
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 help is appreciated in advance. While running the asp page, I still get an error as Error Type: Microsoft VBScript runtime (0x800A000D) Type...
6
9619
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 person has completed it. The format should be "00". For example, if the person puts 1 then it should become 01 and if the person puts 12 in the...
3
5617
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 records a messege shows saying: "Microsoft Access doesn't support the format of the file'file path\filename.jpg' or file is too large.Try converting...
1
3992
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 creating many public properties on the form to do the same thing. At first I tried returning a DataViewRow. This worked fine until I reached the phone...
7
1769
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
9947
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. The trouble is that I'm not really sure how to do this in C# 2005. This was a very useful technique and if anyone could please show me how to...
9
12935
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 convert textbox data into Datatime formate it converted into MM/dd/yyyy formate, but i have a requirement in dd/MM/yyyy formate. please help me, i am...
8
4983
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 string and print it. but i want to use the String.Format() method if possible to do it.
0
7487
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7420
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7680
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7934
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7778
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5349
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4966
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3459
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1033
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.