From: Trans Date: 2007-02-02T22:56:38+09:00 Subject: Re: halving a string On Feb 1, 11:30 pm, "Chris Shea" wrote: > On Feb 1, 9:20 pm, "Trans" wrote: > > untested but... > > > i = [0..str.size / 2].index(' ') > > first_half, second_half = str[0...i], str[i..-1].strip > > > however, you might just prefer > > > require 'facets/core/string/word_wrap' > > str.word_wrap(20) > > > T. > > Tested, and failed. The index returns the position of the very first > space. (Also, it would have to be str[0..(str.size / 2)].index(' ') > but, still, it's no good). To clarify... class String def halve i = size / 2 j = i + self[i..-1].index(' ') return self[0...j].strip, self[j..-1].strip end end T.