473,386 Members | 1,693 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,386 software developers and data experts.

What does {0} do?

In VB.NET code examples I've repeatedly seen numbers between 2 curly braces,
such as {0}, {1}, etc...

Example:
Dim str As String = String.Format("Days Left : {0}. Current DataTime: {1:u}.
\n String: {2}, Float: {3}", val, DateTime.Now, name, num)

What does this mean?
Nov 18 '05 #1
7 1173
They mean the order of variables to be inserted in the string.

For example if you try String.Format(" A is {0} and B is {1}, but when
exchanged A is {1} and B is {0}, "A", "B") you'll see what I mean.

"VB Programmer" <gr********@go-intechN0SPAM.com> 在郵件
news:OD**************@TK2MSFTNGP09.phx.gbl 中撰寫...
In VB.NET code examples I've repeatedly seen numbers between 2 curly braces, such as {0}, {1}, etc...

Example:
Dim str As String = String.Format("Days Left : {0}. Current DataTime: {1:u}. \n String: {2}, Float: {3}", val, DateTime.Now, name, num)

What does this mean?

Nov 18 '05 #2
> In VB.NET code examples I've repeatedly seen numbers between 2 curly
braces,
such as {0}, {1}, etc...

Example:
Dim str As String = String.Format("Days Left : {0}. Current DataTime: {1:u}. \n String: {2}, Float: {3}", val, DateTime.Now, name, num)

What does this mean?


You might want to take a look at
http://msdn.microsoft.com/library/de...rmattopic2.asp.

The MSDN Library is, by the way, usually the first place to look when you
have a syntax question ;)

HTH,

--Florian

===================================
If you wish to contact me directly, send your mail to
florian DOT esser AT gmx DOT de
Nov 18 '05 #3
This is a placeholder. {0} will be replaced by val, {1} by DateTime.Now
etc...

Patrice

"VB Programmer" <gr********@go-intechN0SPAM.com> a 嶰rit dans le message de
news:OD**************@TK2MSFTNGP09.phx.gbl...
In VB.NET code examples I've repeatedly seen numbers between 2 curly braces, such as {0}, {1}, etc...

Example:
Dim str As String = String.Format("Days Left : {0}. Current DataTime: {1:u}. \n String: {2}, Float: {3}", val, DateTime.Now, name, num)

What does this mean?

Nov 18 '05 #4
Thanks everyone!

"Lau Lei Cheong" <la****@yahoo.com.hk> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
They mean the order of variables to be inserted in the string.

For example if you try String.Format(" A is {0} and B is {1}, but when
exchanged A is {1} and B is {0}, "A", "B") you'll see what I mean.

"VB Programmer" <gr********@go-intechN0SPAM.com> 在郵件
news:OD**************@TK2MSFTNGP09.phx.gbl 中撰寫...
In VB.NET code examples I've repeatedly seen numbers between 2 curly

braces,
such as {0}, {1}, etc...

Example:
Dim str As String = String.Format("Days Left : {0}. Current DataTime:

{1:u}.
\n String: {2}, Float: {3}", val, DateTime.Now, name, num)

What does this mean?


Nov 18 '05 #5
Why do this:
Response.Write(String.Format("First:{0}, Second:{1}", Var1, Var2))

Versus just doing this

Response.Write("First:" & Var1 & ", Second:" & Var2)

?
"Patrice" <no****@nowhere.com> wrote in message
news:em**************@TK2MSFTNGP12.phx.gbl...
This is a placeholder. {0} will be replaced by val, {1} by DateTime.Now
etc...

Patrice

"VB Programmer" <gr********@go-intechN0SPAM.com> a 嶰rit dans le message de news:OD**************@TK2MSFTNGP09.phx.gbl...
In VB.NET code examples I've repeatedly seen numbers between 2 curly

braces,
such as {0}, {1}, etc...

Example:
Dim str As String = String.Format("Days Left : {0}. Current DataTime:

{1:u}.
\n String: {2}, Float: {3}", val, DateTime.Now, name, num)

What does this mean?


Nov 18 '05 #6

"VB Programmer" <gr********@go-intechN0SPAM.com> wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl...
Why do this:
Response.Write(String.Format("First:{0}, Second:{1}", Var1, Var2))

Versus just doing this

Response.Write("First:" & Var1 & ", Second:" & Var2)

?


1) easier to read (for humans)
2) probably (can anyone confirm?) better performance than pasting together a lot of strings

Hans Kesting
Nov 18 '05 #7
Flexibility. You have just to use "Premier : {0}, second : {1}." for the
French version or you can use "{1} comes after {0}." instead.

Especially if the format string itself is not hardcoded in the application,
it doesn't even require a code change.

Patrice
"VB Programmer" <gr********@go-intechN0SPAM.com> a 嶰rit dans le message de
news:%2****************@TK2MSFTNGP11.phx.gbl...
Why do this:
Response.Write(String.Format("First:{0}, Second:{1}", Var1, Var2))

Versus just doing this

Response.Write("First:" & Var1 & ", Second:" & Var2)

?
"Patrice" <no****@nowhere.com> wrote in message
news:em**************@TK2MSFTNGP12.phx.gbl...
This is a placeholder. {0} will be replaced by val, {1} by DateTime.Now
etc...

Patrice

"VB Programmer" <gr********@go-intechN0SPAM.com> a 嶰rit dans le message

de
news:OD**************@TK2MSFTNGP09.phx.gbl...
In VB.NET code examples I've repeatedly seen numbers between 2 curly

braces,
such as {0}, {1}, etc...

Example:
Dim str As String = String.Format("Days Left : {0}. Current DataTime:

{1:u}.
\n String: {2}, Float: {3}", val, DateTime.Now, name, num)

What does this mean?



Nov 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
3
by: Chris Cioffi | last post by:
I started writing this list because I wanted to have definite points to base a comparison on and as the starting point of writing something myself. After looking around, I think it would be a...
65
by: perseus | last post by:
I think that everyone who told me that my question is irrelevant, in particular Mr. David White, is being absolutely ridiculous. Obviously, most of you up here behave like the owners of the C++...
125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
3
by: Jukka K. Korpela | last post by:
I have noticed that the meaning of visibility: collapse has been discussed on different forums, but with no consensus on what it really means. Besides, implementations differ. The specification...
7
by: Dan V. | last post by:
Situation: I have to connect with my Windows 2000 server using VS.NET 2003 and C# and connect to a remote Linux server at another company's office and query their XML file. Their file may be...
44
by: lester | last post by:
a pre-beginner's question: what is the pros and cons of .net, compared to ++ I am wondering what can I get if I continue to learn C# after I have learned C --> C++ --> C# ?? I think there...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
669
by: Xah Lee | last post by:
in March, i posted a essay What is Expressiveness in a Computer Language, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
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:
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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,...
0
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...
0
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,...

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.