Console.ReadLine(“Default Text Editable Text On Li

2019-01-26 06:59发布

问题:

Is there way of achieving this? I want to pass some text and have it appear on the input line -- instead of "Enter your Name:<cursor>", I want "Enter your Name:Default Editable Text<cursor>"

回答1:

Ok, found it. Sorry.

static void Main(string[] args)
{
    Console.Write("Your editable text:");
    SendKeys.SendWait("hello"); //hello text will be editable :)
    Console.ReadLine();
}


回答2:

Assign the default value to your string and replace it only if the user has entered something.

Dim name, s As String

name = "John"
Console.Write($"Enter your Name (hit <Enter> for ""{name}""): ")
s = Console.ReadLine()
If Trim(s) <> "" Then
    name = s
End If
Console.WriteLine("Result = {0}", name)
Console.ReadKey()