Format output to 40 characters long per line

后端 未结 3 622
长发绾君心
长发绾君心 2021-01-26 08:41

I\'m fairly new to Ruby and I\'ve been searching Google for a few hours now. Does anyone know how to format the output of a print to be no more than 40 characters long?

3条回答
  •  日久生厌
    2021-01-26 08:49

    puts x.join(" ").scan(/(.{1,40})(?:\s|$)/m)
    

    This is a simple sentence. This simple
    sentence appears on three lines.

提交回复
热议问题