How to remove carriage returns from string but leave line feeds?
-
25-10-2019 - |
Question
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...
Solution
Use the destructive version of the method to actually modify the variable string
.
string.gsub! "\r", ""
OTHER TIPS
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"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow