hello everyone.
any one like to share some experience about ruby string
just like java: trim(), split(), or indexOf()
all regards
···
--
Posted via http://www.ruby-forum.com/.
hello everyone.
any one like to share some experience about ruby string
just like java: trim(), split(), or indexOf()
all regards
--
Posted via http://www.ruby-forum.com/.
joe-black wrote:
hello everyone.
any one like to share some experience about ruby string
just like java: trim(), split(), or indexOf()
Java split() => Ruby String.split:
"hello world".split( " ")
returns [ "hello", "world" ].
Java trim() => Ruby String.strip:
" hello world ".strip
returns "hello world".
Java indexOf() => Ruby String.index
"hello world".index( "w")
returns 6.
--
Posted via http://www.ruby-forum.com/\.
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
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
--
http://ruby.brian-schroeder.de/
Stringed instrument chords: http://chordlist.brian-schroeder.de/
that's cool.
any more? the frequently used.
--
Posted via http://www.ruby-forum.com/.
irb(main):001:0> "foo".upcase
=> "FOO"
irb(main):002:0> "foo".sub(/[aeiou]/, 'a')
=> "fao"
irb(main):003:0> "foo".gsub(/[aeiou]/, 'a')
=> "faa"
irb(main):004:0> "FOO".downcase
=> "foo"
irb(main):005:0> "foo".capitalize
=> "Foo"
irb(main):006:0> "foo".tr("aeiou", "QWRTY")
=> "fTT"
irb(main):007:0> "foo".rjust(10)
=> " foo"
irb(main):008:0> String.help
The last one only works if you have ihelp installed. If not, install it or do
"foo".methods.sort
On Wed, Nov 16, 2005 at 01:09:17AM +0900, Joe Black wrote:
that's cool.
any more? the frequently used.
--
Esteban Manchado Velázquez <zoso@foton.es> - http://www.foton.es
EuropeSwPatentFree - http://EuropeSwPatentFree.hispalinux.es