Console.ReadLine(“Default Text Editable Text On Line”)

ε祈祈猫儿з 提交于 2019-11-28 03:10:35

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!