# Is the design of lpad wrong?

I debugged today the columns no aligning OK on displaying a table, and found that the problem boiled down to the behaviour of lpad. Say I am using lpad to pad the titles of columns to width 5.
Now consider

julia> s=“Ã”
“Ã”

julia> textwidth(s)
1

4


So s is not padded enough! This is according to the specification of lpad which works in terms of
codepoints and

julia> length(s)
2


But I feel that this makes lpad not the right function for padding. My questions are:

• Is this a known problem?
• Could this be changed in the future?
• Are there circumstances where you want lpad to use codepoints instead of textwidth?
2 Likes

Is “Ã” be internally two symbols? An A and tilde?

You get it by typing at the repl “A\tilde<tab>”

1 Like
1 Like

Thanks for the pointer! I will thus use my own version

my_lpad(s,n)=" "^(n-textwidth(s))*s