How to remove carriage returns from string but leave line feeds?
-
25-10-2019 - |
문제
I have a huge String containing many many lines and there are several lines inluding a carrieage return which shouldnt be there! I want to remove the carriage returns and leave the line feeds!
I alread tryed this:
string.gsub "\r", ""
But it didnt do anything!
// Your right I had another problem that was related to this sry...
해결책
Use the destructive version of the method to actually modify the variable string
.
string.gsub! "\r", ""
다른 팁
It works:
[1] pry(main)> str = "a\n\rb\nc\rd\n\ne\r\r"
=> "a\n\rb\nc\rd\n\ne\r\r"
[2] pry(main)> str.gsub("\r", "")
=> "a\nb\ncd\n\ne"
제휴하지 않습니다 StackOverflow