From: "David A. Black" Date: 2004-12-12T09:22:45+09:00 Subject: Re: Find every location of "th" in string. Hi -- On Sun, 12 Dec 2004, Jamis Buck wrote: > On 09:07 Sun 12 Dec , William James wrote: >> Find location of every "th" in "the thin man thinks". >> >> In Icon: >> >> every write(find("th", "the thin man thinks")) >> >> 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? > > Perhaps, if I'm understanding what the Icon snippet does: > > "the thin man thinks".scan( /th/ ) { p $& + $' } I think he wanted the offsets, which could be gotten at like this: "the thin man thinks".scan(/th/) { p $~.offset(0)[0] } David -- David A. Black dblack@wobblini.net