# Is the design of lpad wrong?

**URL:** https://discourse.julialang.org/t/is-the-design-of-lpad-wrong/27494
**Category:** General Usage
**Created:** [August 13, 2019, 11:07am UTC](https://discourse.julialang.org/t/is-the-design-of-lpad-wrong/27494 "2019-08-13T11:07:41Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Jean\_Michel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jean_michel/32/8282_2.png) [@Jean\_Michel](https://discourse.julialang.org/u/Jean_Michel)
#### Post date: [August 13, 2019, 11:07am UTC](https://discourse.julialang.org/t/is-the-design-of-lpad-wrong/27494/1 "2019-08-13T11:07:41Z")

</div>

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
julia> textwidth(s)
1

julia> textwidth(lpad(s,5))
4

```

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

```julia
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?

---

<div class="post-metadata">

### Author: ![epogrebnyak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/epogrebnyak/32/6287_2.png) [@epogrebnyak](https://discourse.julialang.org/u/epogrebnyak)
#### Post date: [August 13, 2019, 11:38am UTC](https://discourse.julialang.org/t/is-the-design-of-lpad-wrong/27494/2 "2019-08-13T11:38:11Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Jean\_Michel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jean_michel/32/8282_2.png) [@Jean\_Michel](https://discourse.julialang.org/u/Jean_Michel)
#### Post date: [August 13, 2019, 11:40am UTC](https://discourse.julialang.org/t/is-the-design-of-lpad-wrong/27494/3 "2019-08-13T11:40:25Z")

</div>

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

---

<div class="post-metadata">

### Author: ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)
#### Post date: [August 13, 2019, 12:18pm UTC](https://discourse.julialang.org/t/is-the-design-of-lpad-wrong/27494/4 "2019-08-13T12:18:01Z")

</div>

[https://github.com/JuliaLang/julia/pull/25069](https://github.com/JuliaLang/julia/pull/25069)

---

<div class="post-metadata">

### Author: ![Jean\_Michel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jean_michel/32/8282_2.png) [@Jean\_Michel](https://discourse.julialang.org/u/Jean_Michel)
#### Post date: [August 13, 2019, 12:40pm UTC](https://discourse.julialang.org/t/is-the-design-of-lpad-wrong/27494/5 "2019-08-13T12:40:23Z")

</div>

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

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