Ruby 文字列の右側にある半角空白を除去するサンプル

環境
Windows11 pro 64bit
ruby ruby 3.0.3p157

構文
文字列.rstrip
文字列の右側にある半角空白を除去するには「rstrip」を使用します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
p " ss ".rstrip
p " tt ".rstrip
p " y y y ".rstrip
p " ss ".rstrip p " tt ".rstrip p " y y y ".rstrip
p " ss ".rstrip

p "    tt    ".rstrip

p "    y y y    ".rstrip

実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
" ss"
" tt"
" y y y"
" ss" " tt" " y y y"
" ss"
"    tt"
"    y y y"

 

Ruby

Posted by arkgame