How to know if 2 ASCII created lines in a command prompt has the same length?

Joined
Sep 26, 2022
Messages
16
Programming Experience
1-3
Is there a way to know if these 2 lines have the same size in pixels aka length? What code should I use to determine if they have the same length or not?

Just because these perpendicular lines created with ASCII, they differ in length size according to whether they were put next to one another or line by line under each other or not.

1666094562177.png
 
If you have the font you can get the size in width of text and use font height to calculate. This example seems to produce about equal width and height of text:
C#:
// using System.Drawing;
// using System.Windows.Forms;

var s = new string('*', 40);
Console.WriteLine(s);
var font = new Font("Consolas", 16);
var size = TextRenderer.MeasureText(s, font);
var lines = size.Width / font.Height;
for (int i = 0; i < lines; i++)
    Console.WriteLine("*");
 
This really depends on the font being used, the kerning between characters, and the leading between lines being what is displaying the text. You can't always assume that output will be a particular "console" device. In fact, you can't even assume that the output will be raster based with pixels. Some people have been switching to using Windows Terminal from the default console.
 
Last edited:
Back
Top Bottom