سؤال

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