ok, I have the following, very simple code:
f = \"String1\\n\\n\\nString2\\n\\n\\n\"
f.each_line do |t|
t.delete! \"\\n\"
puts t.inspect
end
<
f = "String1\n\n\nString2\n\n\n"
f.each_line.collect(&:chomp).reject(&:empty?)
#=> ["String1", "String2"]
The collect(&:chomp)
removes line endings. reject(&:empty?)
throws away all of the empty lines.
You could split the string by \n
, and then reject any blank lines:
f = "String1\n\n\nString2\n\n\n"
f.split("\n").reject { |i| i.empty? }
#=> ["String1", "String2"]
You'd end up with an Array that you can output as you'd like.
f.squeeze("\n").each_line do |l|
puts l
end