🌊

[Feature #21552] String#strip で削除する空白文字を指定できるようにする提案

に公開

[Feature #21552] allow String.strip and similar to take a parameter similar to String.delete

str = "  hoge \n  "
pp str.strip # => "hoge"
# " " と "\t" 文字のみ前後の文字から取り除く
pp str.strip(" \t")
  • これ、最近ほしいと思っていて日本語だと『全角スペースを取り除く』みたいなことをしたいことがあるんですが String#strip だと全角スペースみたいなのは対象外なんですよねえ…
# 全角スペースは対象外
str = "  ああああ   "
pp str.strip # "  ああああ   "
  • なのでこういう機能があるとよいのですが特に進展はなさそう
GitHubで編集を提案

Discussion