Logo

Programming-Idioms

History of Idiom 216 > diff from v4 to v5

Edit summary for version 5 by Bart:
Linked to idiom #215 [Pad string on the left]

Version 4

2020-04-15, 21:30:41

Version 5

2020-04-15, 21:30:45

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. the with s = "abcd", m=10 and c="X" the result should be "XXXabcdXXX".

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. the with s = "abcd", m=10 and c="X" the result should be "XXXabcdXXX".