2 Replies - 1367 Views - Last Post: 27 May 2015 - 07:55 PM Rate Topic: -----

#1 J.Hickin91   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 24
  • Joined: 19-May 15

Get all text from console window

Posted 27 May 2015 - 02:46 PM

Hi guys

Is there a way to get all the text in a console window and save it to a string variable. So once I run a Console.Clear() I can just do Console.Write(Previous Text).

Hope you can help
Is This A Good Question/Topic? 0
  • +

Replies To: Get all text from console window

#2 Curtis Rutland   User is offline

  • (╯°□°)╯︵ (~ .o.)~
  • member icon


Reputation: 5106
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: Get all text from console window

Posted 27 May 2015 - 02:54 PM

I'm not sure that there is a component for that. There are ways to capture everything you send to the console, there are ways to redirect console output entirely, but I don't believe there is a way to get the currently displayed text in the console.

On the other hand, why bother? If all you want to do is replace some text, use Console.SetCursorPosition.

https://msdn.microso...(v=vs.110).aspx

You can use it to overwrite what's currently on the screen. If you were going to get everything, modify it, then write it back out, you might as well just move the cursor to the part you need to change and change it directly.
Was This Post Helpful? 0
  • +
  • -

#3 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7915
  • View blog
  • Posts: 26,430
  • Joined: 05-May 12

Re: Get all text from console window

Posted 27 May 2015 - 07:55 PM

Or you could use P/Invoke to call ReadConsoleOutputCharacter().
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1