I need to clear a certain line in a console, but need to keep the rest.
I know of Console.Clear(), but clears the whole console.
How do I just clear one line?
I have decided to answer my own question because I have googled this and nobody seems to have a method.
Since there wasn't a clearLine() / ClearLine() method, I made one.
Here it is:
private static void clearLine()
{
Console.Write(new string(' ', Console.BufferWidth - Console.CursorLeft));
}
other possibilities:
private static void clearLine(int left, int top)
{
int pLeft = Console.CursorLeft;
int pTop = Console.CursorTop;
Console.setCursorPosition(left, top);
Console.Write(new string(' ', Console.BufferWidth - Console.CursorLeft));
Console.setCursorPosition(pLeft, pTop);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With