「Ruby」stripで文字列の前後にある半角空白を除去する

構文
文字列.strip
「strip」を使用して文字列の前後にある半角空白を除去します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#!/usr/bin/ruby
p " study ".strip
p " study ".strip
p " s t u d y ".strip
#!/usr/bin/ruby p " study ".strip p " study ".strip p " s t u d y ".strip
#!/usr/bin/ruby
p " study ".strip
p "   study    ".strip
p "    s t u d y   ".strip

実行結果

“study"
“study"
“s t u d y"

Ruby

Posted by arkgame