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

環境
Windows11 Pro 64bit
ruby 3.1.2p20

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

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
p " study ".lstrip
p " arkgame ".lstrip
p " s t d ".lstrip
p " study ".lstrip p " arkgame ".lstrip p " s t d ".lstrip
p " study ".lstrip

p "    arkgame    ".lstrip

p "    s t d    ".lstrip

実行結果
“study "
“arkgame "
“s t d “

Ruby

Posted by arkgame