Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi experts,

I'd like to print some text to the Visual Studio built-in debug console. For that I use the following code:
C#
Console.Write("Printing my text here.");
Now I would like to overwrite "Printing" with "Writing ":
C#
Console.Write("\rWriting ");
But the carriage return does a newline on its own.

How can I continue writing at the beginning of the new line in Visual Studio's output window?

Console.SetCursorPosition causes an "Invalid handle" IOException.
Console.Write("\b"); prints a white circle on black background.
Posted

1 solution

You can't, AFAIK - it's not meant for "normal" console activity and interaction. Instead, build a string (or StringBuilder) containing the data you want to output, modify that, and then use Console.Write
 
Share this answer
 
Comments
lukeer 11-Dec-13 6:08am    
Yeah, I was already afraid it would turn out that way.

But the change has to be done after processing the interesting part. And it's quite possible that the processing itself can fail. In that case, nothing would get printed at all.
So I'll leave it the way it is and print the result on the next line. That's not as neat but will do.
OriginalGriff 11-Dec-13 6:09am    
It's only for debugging anyway! :laugh:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900