From: Neil Stevens Date: 2004-12-12T09:32:33+09:00 Subject: Re: Find every location of "th" in string. On Sat, 11 Dec 2004 16:05:56 -0800, William James wrote: > In Ruby: > > s='the thin man thinks' > t='th' > (0...s.size).each{|x| puts x if s[x,t.size]==t} > > Is there a better way? This is what comes to my mind: needle = 'th' x = 0 'the thin man thinks'.split(needle).each do |s| puts x x += needle.length + s.length end -- Neil Stevens - neil@hakubi.us "The world is a dangerous place to live; not because of the people who are evil, but because of the people who don't do anything about it." -- Albert Einstein(?)