Re: A simple C# Q. How to print "{0}"?
From: gerry (germ_at_hotmail.com)
Date: 05/22/04
- Next message: Bill English: "Word Count"
- Previous message: Robert Misiak: "Re: A simple C# Q. How to print "{0}"?"
- In reply to: Robert Misiak: "Re: A simple C# Q. How to print "{0}"?"
- Next in thread: Brian Henry: "Re: A simple C# Q. How to print "{0}"?"
- Reply: Brian Henry: "Re: A simple C# Q. How to print "{0}"?"
- Reply: mikeb: "Re: A simple C# Q. How to print "{0}"?"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 22 May 2004 00:35:24 -0400
I don't understand the original question and I am flabergasted by the
responses.
It sounds like the op is trying to print the string "{0}" to the console
along with some other values.
However he has answered his own question :
Console.WriteLine("Hello {{0}} {0}", "John");
displays :
Hello {0} John
which is exactly what it sounds like he is trying to do.
the second line gives an error , and it should - so don't do it that way.
string.format("text {0}","value of 0") : huh ?
this generates "text value of 0" , how is that printing "{0}" ?
Console.WriteLine ( String.Format ("Hello {0}", "John") ); huh ?
this generates "Hello John" , how is that printing "{0}" ?
also : why bother with string.Format() when Console.WriteLine() has this
formatting capability already.
"Robert Misiak" <rmisiak@EARTH-cut.this.part.out-LINK.net> wrote in message
news:ZzArc.4478$Tn6.3157@newsread1.news.pas.earthlink.net...
> You need to use String.Format. String.Format("Hello {0}", "John") will
> return the string "Hello John".
>
> Console.WriteLine ( String.Format ("Hello {0}", "John") );
>
> Robert
>
>
> "Tony" <anonymous@discussions.microsoft.com> wrote in message
> news:758C47E9-2283-4BE2-9C5F-F08B937C0868@microsoft.com...
> > Hello,
> >
> > I am learning C# and encountered the following problem when I tried to
> figure out how to print
> > the string {0} in a Console window.
> > The following piece of codes complied OK. But when I ran it, it failed.
> > The codes are:
> >
> >
> > using System;
> > class Test1
> > {
> > public static void Main()
> > {
> > Console.WriteLine("Hello {{0}} {0}", "John"); // Hello {0} John
> > Console.WriteLine("Hello {{0} {0}", "John"); // Error
> > }
> > }
> >
> >
> > Thanks.
> >
> > Tony
> >
>
>
- Next message: Bill English: "Word Count"
- Previous message: Robert Misiak: "Re: A simple C# Q. How to print "{0}"?"
- In reply to: Robert Misiak: "Re: A simple C# Q. How to print "{0}"?"
- Next in thread: Brian Henry: "Re: A simple C# Q. How to print "{0}"?"
- Reply: Brian Henry: "Re: A simple C# Q. How to print "{0}"?"
- Reply: mikeb: "Re: A simple C# Q. How to print "{0}"?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|