Reputation: 1547
I want a user of my console application could update text which was written by Console.Write(); For example:
var currentVar="bla-bla-bla";
Console.Write(currentVar);
var newVar=Console.Read();//here user can update previous output of Write() method;
Console.Write(newVar);//output of updated value
Is it possible?
Upvotes: 1
Views: 1905
Reputation: 10055
I think this is what you are trying to do.
Console.WriteLine("Original");
var newVar=Console.Read();
Console.SetCursorPosition(0, Console.CursorTop -2); // Where -2 moves the cursor two lines up.
Console.WriteLine(newVar);
Then however you will be overwriting the next lines because the cursor will just move down. You will need to use the COnsole.SetCursorPosition again to put the cursor back to where you want it.
Upvotes: 1
Reputation: 223402
Console.Read
doesn't read the previous output, instead it wait for the input.
Reads the next character from the standard input stream.
The Read method blocks its return while you type input characters; it terminates when you press the Enter key. Pressing Enter appends a platform-dependent line termination sequence to your input (for example, Windows appends a carriage return-linefeed sequence). Subsequent calls to the Read method retrieve your input one character at a time. After the final character is retrieved, Read blocks its return again and the cycle repeats.
If you intentd to overwrite previous output with the new content, then use Console.SetCursorPosition
. Also see this answer
Upvotes: 1
Reputation: 88
You should replace StandardOutput by your own implementation and catch the written text, then do whatever you want with it...
Upvotes: 0