From: James Edward Gray II Date: 2005-10-04T22:41:28+09:00 Subject: Re: Wrapping strings On Oct 3, 2005, at 9:25 PM, Ben wrote: > I have a string containing multiple lines that I would like to put > into a C++ file as a comment: > desc = "" > while (line = gets) !~ /^\.$/ > desc += "#{line}" > end > > I'd like to precede each line with a "// " to make it a comment, and > I'd like to wrap each line by the 78th character. > > I don't suppose there is any way to do this quick and simple like? Here's a cool hack by Erik Terpstra for word wrapping normal text: irb(main):001:0> str = 'This is a test of the emergency broadcasting services' => "This is a test of the emergency broadcasting services" irb(main):002:0> str.scan(/(.{1,30})(?:\s+|$)/).flatten.join("\n") => "This is a test of the\nemergency broadcasting\nservices" Hope that gives you some ideas. James Edward Gray II