文字列のセンタリング
Posted feedbacks - OCaml
1 2 3 4 5 6 7 | let center str width =
let len = String.length str in
if width>len then
let res = String.make width ' ' in
(String.blit str 0 res ((width-len)/2) len; res)
else
String.sub str ((len-width)/2) width ;;
|


nobsun
#4089()
Rating0/2=0.00
文字列を指定のカラム幅にセンタリング配置する関数を示してください。文字列の長さが指定した幅より長い場合には文字列の両端をできるだけ均等に切り落して指定幅に収めてください。1文字は1カラムに収まるものと仮定してかまいません。
[ reply ]