get "default" text from the console
- From: per9000 <per9000@xxxxxxxxx>
- Date: 25 Apr 2007 01:20:53 -0700
Hi,
can I print some default text on the console when doing a ReadLine?
A silly example below shows two small scenarios. In the first a user
is told what he appears to be called, and asks for a name.
In the second case I want the the user to be able to just press return
to accept the username of the system. (I understand it does not work
the way I do it below - I just want to illustrate what I want).
Thanks,
P9K
---------
using System;
using System.Text;
namespace FeedMeName
{
class Program
{
static void Main(string[] args)
{
string name1 = Environment.UserName;
Console.WriteLine("Are you '{0}'?", name1);
Console.Write("name please >> ");
name1 = Console.ReadLine();
Console.WriteLine("Hello '{0}'!", name1);
string name2 = Environment.UserName;
Console.WriteLine("Are you '{0}'?.", name2);
Console.Write("name please >> ");
Console.Write(name2);
Console.CursorLeft -= name2.Length;
name2 = Console.ReadLine();
Console.WriteLine("Hello '{0}'!", name2);
}
}
}
---------
FeedMeName.exeAre you 'per'?
name please >> my name is foobar
Hello 'my name is foobar'!
Are you 'per'?.
name please >> foobar, goddamit
Hello 'foobar, goddamit'!
---------
FeedMeName.exeAre you 'per'?
name please >> fo
Hello 'fo'!
Are you 'per'?.
name please >> brr
Hello 'br'!
.
- Follow-Ups:
- Re: get "default" text from the console
- From: Jon Skeet [C# MVP]
- Re: get "default" text from the console
- Prev by Date: Re: Collection property & Design Time support
- Next by Date: Re: Active Directory query doesn't work...
- Previous by thread: Problem with WebService
- Next by thread: Re: get "default" text from the console
- Index(es):
Relevant Pages
|