I have a ruby file that reads files and splits the text into an array using split(' '). The problem is that these text files contain newline characters, and I would like to retain those newline characters. For example, if I run the following code
"Lorem ipsum\ndolor sit amet".split(' ')
I get the output of
["Lorem", "ipsum", "dolor", "sit", "amet"]
Why does split remove the newline character? How can i retain \n in my array?
Michael Berkowski’s comment on your question is correct.
If you want to work around this case, use a regular expression: