问题
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()
来源:https://stackoverflow.com/questions/8962691/console-readlinedefault-text-editable-text-on-line