Re: A simple C# Q. How to print "{0}"?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: gerry (germ_at_hotmail.com)
Date: 05/22/04


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
> >
>
>



Relevant Pages

  • Re: Check if String has a number
    ... Your original question was basically "how do I determine if there is a digit in my text"? ... >>> xStr can contain a string which includes numbers or not contain ... >>> Ron ... If the string starts with a non-numerical character it ...
    (microsoft.public.vb.general.discussion)
  • Re: Again: Opinions on Carvin basses NOT POLITICS!
    ... Anyhow back to my original question. ... What do people think about Carvin basses? ... Seems to me that with this string the articulation of the B string comes through a lot better. ... p.s. thanks to the newsgroup contributors past and present - you guys have been advising me for years. ...
    (alt.guitar.bass)
  • RE: Help needed with reference formula
    ... Optional Seperator As String = ", ... FindRelation = Left- Len) ... here is a brief overview of the database. ... ID's where the original Question ID in Column A appears. ...
    (microsoft.public.excel.misc)
  • Re: Java Applet saving results on home server
    ... I can also store the results to a string and write that to a ... that has some data structures to store all the things I need, ... This puts you right back into your original question. ... I've got a problem with the Jakarta ftp client. ...
    (comp.lang.java.help)
  • How to iterate through a (semicolon;separated;list)
    ... Aaarggghh, sorry about the messed up title of my earlier post. ... In the meantime, I have an answer, but it is not wholly satisfying ... The original question was to find out how I can iterate through ... 'replace string' in my arsenal. ...
    (microsoft.public.win2000.cmdprompt.admin)