开发者

Add a new line in file?

I want to add a new line after a string is inserted.

My current code looks like this:

  File.open(filename, 'a') do |file|
    file.write @string
  end

How could I add a new line after th开发者_Go百科e string is inserted?


Use IO#puts.

file.puts @string


file.write "\n"


In case if you can't use IO#puts:

file.write "text#{$/}"

where $/ represents OS-dependent new line separator.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜