From: Robert Klemme Date: 2005-05-17T01:55:30+09:00 Subject: Re: determining common characters from start of two strings? "David A. Black" schrieb im Newsbeitrag news:Pine.LNX.4.61.0505160448390.24570@wobblini... Hi -- On Mon, 16 May 2005, [ISO-8859-1] Brian Schr�der wrote: > class String > def lcommon(other) > 0.upto(length) do | i | return i if other[i] != self[i] end > length > end > end You can also use the return value of times to do this: class String def lcommon(other) length.times do |i| return i if other[i] != self[i] end end end (I had been toying with this but using break instead of return, which was giving me problems :-) Hey, this is nice! robert