On 15/11/05, Joe Black <allenbobo / gmail.com> wrote:
> hello everyone.
> any one like to share some experience about ruby string
> just like java: trim(), split(), or indexOf()
>
> all regards
>
>
>

Reading the pickaxe and
$ ri String
would be a good idea.

One neat thing I onlz found a few month ago is this
irb(main):001:0> "my string with 28 characters"[/\d+/]
=> "28"
irb(main):002:0> s = "my string with 28 characters"
=> "my string with 28 characters"
irb(main):003:0> bschroed@black:~/svn$ irb1.8
irb(main):001:0> s = "my string with 28 characters"
=> "my string with 28 characters"
irb(main):002:0> s[/\d+/]
=> "28"
irb(main):003:0> s[/\d+/] = "twentyeight"
=> "twentyeight"
irb(main):004:0> s
=> "my string with twentyeight characters"
irb(main):005:0> s[/string (\w+) (\w+)/]
=> "string with twentyeight"
irb(main):006:0> s[/string (\w+) (\w+)/, 1]
=> "with"
irb(main):007:0> s[/string (\w+) (\w+)/, 2]
=> "twentyeight"

Especially line three is really cool.

cheers,

Brian

--
http://ruby.brian-schroeder.de/

Stringed instrument chords: http://chordlist.brian-schroeder.de/