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

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

cpad("woof", 8)

would yield:

"  woof  "
1 Like

Apparently there is in base somewhere.

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

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

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

1 Like

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

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?

Created a github issue to help resolve this: