Trim blank newlines from string in Ruby -
I have a string of four empty rows, which make up eight lines in the following:
str = "aaa \ n \ n \ nbbb \ n \ nccc \ ddd \ n"
I want to return it all in one line, the output should be on the same line :
aabbcdd
I used different trim function to get the output but I still failed.
Which method do I have here?
Ruby (and slightly lesser Pearl-way):
New_str = str.delete "\ n"
... or if you want to in-place it:
str.delete! "\ N"
Comments
Post a Comment