Ben <benbelly / gmail.com> writes: >I have a string containing multiple lines that I would like to put >into a C++ file as a comment: >desc =3D "" >while (line =3D gets) !~ /^\.$/ > desc +=3D "#{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? >I figure I need to pull out the carriage returns, but then I can't >think of anything pretty after that. Any tips? I recommend getting the text-format module (available from the RAA at http://rubyforge.org/projects/text-format or as a gem) and using it. If that doesn't fit your needs for some reason, you can do it manually. Something like this should work: words = line.split(/\s+/) while words do line = '// ' while words && line.length < 78 do line += words.shift + ' ' end puts line end >-Ben