# Is there native function for cpad (center version of lpad/rpad)?

**URL:** https://discourse.julialang.org/t/is-there-native-function-for-cpad-center-version-of-lpad-rpad/4045
**Category:** General Usage
**Tags:** question
**Created:** [June 1, 2017, 9:14pm UTC](https://discourse.julialang.org/t/is-there-native-function-for-cpad-center-version-of-lpad-rpad/4045 "2017-06-01T21:14:08Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)
#### Post date: [June 1, 2017, 9:14pm UTC](https://discourse.julialang.org/t/is-there-native-function-for-cpad-center-version-of-lpad-rpad/4045/1 "2017-06-01T21:14:08Z")

</div>

Is there a function in the native library to pad a string with ~equal spaces on both sides?

```julia
cpad("woof", 8)

```

would yield:

```julia
" woof "

```

---

<div class="post-metadata">

### Author: ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)
#### Post date: [June 1, 2017, 9:17pm UTC](https://discourse.julialang.org/t/is-there-native-function-for-cpad-center-version-of-lpad-rpad/4045/2 "2017-06-01T21:17:37Z")

</div>

Apparently there is in base somewhere.

I just don’t know how to access it… ☹

[https://github.com/JuliaLang/julia/blob/da69be277435098c94d1a038df01cbc208fac143/base/strings/util.jl#L249](https://github.com/JuliaLang/julia/blob/da69be277435098c94d1a038df01cbc208fac143/base/strings/util.jl#L249)

---

<div class="post-metadata">

### Author: ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)
#### Post date: [June 1, 2017, 9:18pm UTC](https://discourse.julialang.org/t/is-there-native-function-for-cpad-center-version-of-lpad-rpad/4045/3 "2017-06-01T21:18:07Z")

</div>

```julia
julia> Base.cpad("March", 10)
" March "

```

---

<div class="post-metadata">

### Author: ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)
#### Post date: [June 1, 2017, 9:18pm UTC](https://discourse.julialang.org/t/is-there-native-function-for-cpad-center-version-of-lpad-rpad/4045/4 "2017-06-01T21:18:52Z")

</div>

Seems like there’s a whole host of string manipulation functions that could be moved out into a package.

---

<div class="post-metadata">

### Author: ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)
#### Post date: [June 1, 2017, 9:22pm UTC](https://discourse.julialang.org/t/is-there-native-function-for-cpad-center-version-of-lpad-rpad/4045/5 "2017-06-01T21:22:49Z")

</div>

Also, `cpad` doesn’t work on symbols (like `lpad` and `rpad` do)

---

<div class="post-metadata">

### Author: ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)
#### Post date: [June 1, 2017, 9:41pm UTC](https://discourse.julialang.org/t/is-there-native-function-for-cpad-center-version-of-lpad-rpad/4045/6 "2017-06-01T21:41:08Z")

</div>

```julia
Base.cpad(s::Symbol, i::Integer) = Base.cpad(string(s), i)

```

Seems like `cpad` could be exported if `lpad` and `rpad` are.

I wonder if this is another case where there should just be a single `pad` function that all of these can be rolled into?

---

<div class="post-metadata">

### Author: ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)
#### Post date: [June 2, 2017, 4:28am UTC](https://discourse.julialang.org/t/is-there-native-function-for-cpad-center-version-of-lpad-rpad/4045/7 "2017-06-02T04:28:22Z")

</div>

Created a github issue to help resolve this:

- [issue#22184](https://github.com/JuliaLang/julia/issues/22184)
