From: Gennady Bystritsky Date: 2009-03-05T11:41:07+09:00 Subject: Re: Cut a string each 80 character > -----Original Message----- > From: picpic72@hotmail.com [mailto:picpic72@hotmail.com] > Sent: Wednesday, March 04, 2009 6:06 PM > To: ruby-talk ML > Subject: Cut a string each 80 character > > Hello everyone! > > I want to do cut a string each 80 character. Do you know how to do? > > For instance : > string = "jdskj fjkjjkl > djskfljksldjfkjdkljksljkdjfkdlsjfklsjdkfldsjdkfljkldjksjfkljkdlfjkdsljk > ljfdklskjkdfldfldfjkdfjkldfskjldfskjldfkjldfskjlsdfkjldfskljdfskjldkjld > fkjdfkllkdf" string.scan(%r{.{1,80}}) or n = 80 string.scan(%r{.{1,#{n}}) > > For this string, I want to add
each 80 character for the third > word. string.scan(%r{.{1,80}}).map { |_chunk| _chunk + '
' } Make corresponding adjustments if you want to apply it to a particular word of your string (e.g., do stirng.split.slice(2) for the third word). Hope it helps, Gennady.