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>"
10
-
1This may be a duplicate: stackoverflow.com/q/1655318/1108263 – Brian Snow Jan 22 '12 at 16:51
-
1I think it's moreso a duplicate of stackoverflow.com/questions/7565415/… – Slugart Jan 22 '12 at 16:56
-
This question hasn't solution.... :( – nim Apr 17 '15 at 14:40
13
Ok, found it. Sorry.
static void Main(string[] args)
{
Console.Write("Your editable text:");
SendKeys.SendWait("hello"); //hello text will be editable :)
Console.ReadLine();
}
-
8This will have interesting side-effects when your console window doesn't have the focus. – Hans Passant Jan 22 '12 at 18:18
-
Yes, but I am only doing this immediately following dos line instigation of my program. The program (right now at least) is interactive from the command line and retains session info between calls. Eventually it will not bounce back into dos. – Mark Robbins Jan 23 '12 at 3:04
-
1
-
-
3
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()