문제

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"
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top