L
Li Chen
Hi all,
I have a small script to find a match. If a match is found I need to
print its position within the string. I try the String#index but it only
returns the first match. Any idea?
Thanks,
Li
C:\Documents and Settings\chen73\My Documents\Ruby\bin>irb
irb(main):001:0> "ello-hello".scan('e') do |match|
irb(main):002:1* p "ello-hello".index(match)
irb(main):003:1> end
0
0
=> "ello-hello"
irb(main):004:0>
I have a small script to find a match. If a match is found I need to
print its position within the string. I try the String#index but it only
returns the first match. Any idea?
Thanks,
Li
C:\Documents and Settings\chen73\My Documents\Ruby\bin>irb
irb(main):001:0> "ello-hello".scan('e') do |match|
irb(main):002:1* p "ello-hello".index(match)
irb(main):003:1> end
0
0
=> "ello-hello"
irb(main):004:0>