Hello,
I should like to know what you think of this.
$a = (Get-ChildItem "C:\Ant\videos-mdr.com - Un toboggan vraiment flippant _ il propulse à la verticale ! - Vidéos MDR.mp4").Name.Substring(0,30);
$b = (Get-ChildItem "C:\Ant\1080p - ❤️🍑🍆 Cœur, Pêche, Aubergine Ados, Vie Sexuelle & Affective*.*").Name.Substring(0,30);
$a;$b;Measure-DisplayWidth($a);Measure-DisplayWidth($b);
#Answer:
videos-mdr.com - Un toboggan v
1080p - ❤️🍑🍆 Cœur, Pêche, Au
30
30
Not really vertically aligned … Although the displaywidth is the same.
The characters that show fruits take the width of three letters, whether they are attributed a displaywidth of two. Should I use a more appropriate font?
In ‘Courier New’ $b ends at the g of $a. The length comparison is reversed, and with a bigger difference. Unexpected, no?
With MsGothic $b still has “Au” to display where $a has finished.
I obtain something nearly aligned with MsGothic if I give a character width of 20pt for the letters and figures, and 16pt for the characters that show fruits.
I thought I could avoid to examine each character separately, but if this is the solution to target, I have to take the hexadecimal representation in account, if the upper code is different from 0 I must give a more little width. And I did not have a look at the Korean characters yet.
I wonder whether getting the position of the keyboard cursor after displaying each character would be a good idea. It is theoretically what Measure-DisplayWidth intended to avoid.
In the Windows API there is something to know the display width, that takes the font in account. It is sad to call the Windows API if we have a DisplayWidth function in PowerShell, but if it gives better results … I have to precise that I did not try it in this particular case yet.