Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to delete a character that has just been written using Console.WriteLine?

Is there any way to delete the last character from the console, i.e.

Console.WriteLine("List: apple,pear,"); // Somehow delete the last ',' character from the console. Console.WriteLine("."); // Now the console contains "List: apple,pear." 

Sure, I could create a string first then print that to the console, but I'm just curious to see if I can delete characters directly from the console.

like image 316
Contango Avatar asked Mar 04 '11 15:03

Contango


1 Answers

"\b" is ASCII backspace. Print it to back up one char.

Console.Write("Abc"); Console.Write("\b"); Console.Write("Def"); 

outputs "AbDef";

As pointed out by Contango and Sammi, there are times where overwriting with a space is required:

Console.Write("\b \b"); 
like image 113
John Arlen Avatar answered Oct 04 '22 23:10

John Arlen