Programming-Idioms

History of Idiom 216

Idiom #216 Pad a string in the center

Prepend extra character c at the beginning and ending of string s to make sure its length is at least m.
After the padding the original content of s should be at the center of the result.
The length is the number of characters, not the number of bytes.

E.g. with s="abcd", m=10 and c="X" the result should be "XXXabcdXXX".

#Edit dateEdit SummaryAuthor
👁 Δ 8 2020-05-03, 20:05 [Perl] No sample values programming-idioms.org
👁 Δ 7 2020-04-29, 09:48 New Perl implementation by user [Corion] Corion
👁 Δ 6 2020-04-15, 21:31 Typo programming-idioms.org
👁 Δ 5 2020-04-15, 21:30 Linked to idiom #215 [Pad string on the left] Bart
👁 Δ 4 2020-04-15, 21:30 Linked to idiom #214 [Pad string on the right] Bart
👁 Δ 3 2019-11-04, 19:08 New Python implementation by user [Oldboy] Oldboy
👁 Δ 2 2019-11-04, 01:10 New Ruby implementation by user [steenslag] steenslag
1 2019-11-03, 13:44 Idiom creation by user [Bart] Bart