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

question

#1

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

cpad("woof", 8)

would yield:

"  woof  "

#2

Apparently there is in base somewhere.

I just don’t know how to access it… :frowning:


#3
julia> Base.cpad("March", 10)
"  March   "

#4

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


#5

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


#6
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?


#7

Created a github issue to help resolve this: