From: Harry Kakueki Date: 2009-07-22T09:41:17+09:00 Subject: Re: String spliting and inclusion > > I hope this makes sense, to summarise I want to break up a string into a > max of 50 characters without breaking up words. > > Thanks in advance > > Stuart > -- > > str = "I did not test this completely so you may need to make some adjustments to this, but give it a try. This cuts on twenty instead of fifty characters." (str.length/20).times do arr = str.split(//) ess = arr.zip((0...arr.length).to_a) tee = ess.reverse.detect{|y| y[0] == " " and y[1] <= 20} p str.slice!(0..tee[1]).strip end p str Harry -- A Look into Japanese Ruby List in English http://www.kakueki.com/ruby/list.html