Let me start with an example to illustrate what I mean by "width":
let string1 = "abc" let string2 = "甲乙丙"
string2 contain the same number of characters,
string2 takes 2x as much space as
string1 does when printed in terminal, or anywhere on screen in monospaced fonts. So, each character in
string2 has 2x the width of each in
This becomes a problem if I want to generate a table with all cells well-aligned, because simply using each string's
count property won't be enough:
| abc | ---|-----|--- | 甲乙丙 |
I considered assigning a width of 2 to a scalar if its
true. However, a character is not always a scalar (because of combining characters), and there are also scalars like
U+00A0 that has zero width.
Is there a way to find the width of a character in Swift?