Is there a way to split a bitstring loaded from a file on newlines? I have something like this:
A line of text
Additional line of text
And another line
And I want an array like this:
["A line of text",
"Additional line of text",
"And another line"]
Is there a function to split the text on newlines to produce something like this array?
Thanks in advance.
In addition to Roberts answer.
In Elixir you can use: String.split(string, "\n")
Look at String module.
If you simply split a string on \n
, there are some serious portability problems. This is because many systems use \n
, a few such as older macs use \r
and Windows uses \r\n
to delimit new lines.
The safer way to do it would be to use a regex to match any of the three above possibilities:String.split(str, ~r{(\r\n|\r|\n)}
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With