I need to format a String that ends with a newline. I'd just add a "\n", but I want this to work on Windows too. Many languages have a constant that provides the appropriate CR/LF/CRLF sequence according to the platform, but I can't seem to find anything in Ruby. Does it exist?
我需要格式化以换行符结尾的String。我只想添加一个“\ n”,但我希望这也适用于Windows。许多语言都有一个常量,根据平台提供适当的CR / LF / CRLF序列,但我似乎无法在Ruby中找到任何东西。它存在吗?
1 个解决方案
#1
25
Ruby's got four (!)
Ruby有四个(!)
p $/
p $-0
require 'English'
p $RS
p $INPUT_RECORD_SEPARATOR
Using IO#puts (= File#puts) will take care of the proper EOL, no need to set it manually.
使用IO#puts(= File#puts)将处理正确的EOL,无需手动设置。
#1
25
Ruby's got four (!)
Ruby有四个(!)
p $/
p $-0
require 'English'
p $RS
p $INPUT_RECORD_SEPARATOR
Using IO#puts (= File#puts) will take care of the proper EOL, no need to set it manually.
使用IO#puts(= File#puts)将处理正确的EOL,无需手动设置。