03 - reversing a string by words or characters.rb
来自「O Reilly Ruby Cookbook source code」· RB 代码 · 共 16 行
RB
16 行
s = ".sdrawkcab si gnirts sihT"s.reverse # => "This string is backwards."s # => ".sdrawkcab si gnirts sihT"s.reverse! # => "This string is backwards."s # => "This string is backwards."#---s = "order. wrong the in are words These"s.split(/(\s+)/).reverse!.join('') # => "These words are in the wrong order."s.split(/\b/).reverse!.join('') # => "These words are in the wrong. order"#---"Three little words".split(/\s+/) # => ["Three", "little", "words"]"Three little words".split(/(\s+)/) # => ["Three", " ", "little", " ", "words"]#---
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?