Normalizing line endings in Ruby

后端 未结 4 890
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-29 04:01

I have a string in Ruby, s (say) which might have any of the standard line endings (\\n, \\r\\n, \\r). I want to convert

4条回答
  •  梦谈多话
    2020-12-29 04:24

    I think the cleanest solution would be to use a regular expression:

    s.gsub! /\r\n?/, "\n"
    

提交回复
热议问题