The following CSharp Code(just sample):
Console.WriteLine("Searching file in...");
foreach(var dir in DirList)
{
Console.WriteLine(dir);
}
Prints Output As:
Searching file in...
dir1
dir2
dir3
dir4
.
.
.
Question? How can I get the output as
Searching file in...
dir1
(then clear dir1 and print dir2 and so on)All next dir name wiil replace the previous dir
C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...
In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.
C is a high-level and general-purpose programming language that is ideal for developing firmware or portable applications. Originally intended for writing system software, C was developed at Bell Labs by Dennis Ritchie for the Unix Operating System in the early 1970s.
C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.
Use Console.SetCursorPosition
to set the cursor on the start of the last line and rewrite it.
Something like:
Console.WriteLine(dir);
Console.SetCursorPosition(0, Console.CursorTop - 1);
EDIT:
According to your comment, you could do as follows:
Console.WriteLine("Searching file in...");
foreach (var dir in DirList)
{
ClearCurrentConsoleLine();
Console.Write(dir);
}
With ClearCurrentConsoleLine
defined as:
public static void ClearCurrentConsoleLine()
{
int currentLineCursor = Console.CursorTop;
Console.SetCursorPosition(0, Console.CursorTop);
for (int i = 0; i < Console.WindowWidth; i++)
Console.Write(" ");
Console.SetCursorPosition(0, currentLineCursor);
}
If your problem is clearing the console then use the method Console.Clear();
, if it's not, use this to overwrite the last line;
Console.WriteLine("Searching file in...");
foreach(var dir in DirList)
{
Console.SetCursorPosition(1,0);
Console.WriteLine(dir);
}
You could print using "\r", that way cursor dont jump a line, and you can rewrite it.
foreach(var dir in DirList)
{
Console.Write("\r{0}% ",dir);
}
use spaces after number to make sure everything is erased, and use .Write instead of WriteLine because you dont want to add "\n"
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