Text wrap

Hi,

I have a ruby script that’s doing what I need, and I would like to add
one feature. The script outputs a text file, and I would like Ruby to
take the final text file and wrap it at 67 characters, instead of doing
it manually in the editor.

Is there an available method or something that I can invoke? If so, can
you give me an example of its use (I’m still very much a novice!)

Best
Idris

text = whatever you need to wrap

To print it:
0.step(text.length, 67) {|x| puts text[x, x+67]}

To put it in another variable:
wrapped = “”
0.step(text.length, 67) {|x| wrapped << “\n” << text[x, x+67]}

Dan

ishamid wrote:

Best
Idris

X = 10 # Width is 10 characters.
str =
“This\nis a test of the emergency broadcasting servicings I
asseverate”
p str.gsub(/\n/," ").scan(/\S.{0,#{X-2}}\S(?=\s|$)|\S+/)