Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a string bold in a console window?

Tags:

c#

So I'm trying to find a simple code that makes my code get printed in bold. When I searched the internet all of them were so complicated that it wasn't even worth it. Is there any easier way to make a string or just a Console.WriteLine(" "); bold?

Console.Write("Type in the number of people to create: ");
int time = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nGenerating " + time + " people please stand by...");
System.Threading.Thread.Sleep(3000);
Console.Clear();
like image 202
user12929842 Avatar asked Dec 31 '22 07:12

user12929842


1 Answers

You can use the ANSII escape codes, as long as your console supports it.

You can do basics like, color text, background and bold,underline and reverse colors. for example in c#

Console.WriteLine("\x1b[1mTEST\x1b[0m");

will print it in bold \x1b[0m one at the end is to reset the formatting, many formatting options are made by changing the number after the bracket.

look into these links, I have used it with C and Python in bash, but I'm not sure about C# at the moment.

https://www.jerriepelser.com/blog/using-ansi-color-codes-in-net-console-apps/

ANSI-Coloring Console Output with .NET

This link has all the codes for ANSII escape codes, I have used it in C, so It may need some modifications.

http://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html

like image 63
Atreyagaurav Avatar answered Jan 02 '23 19:01

Atreyagaurav