I got a string from "text_area_tag". Because the browser working on
windows while my rails server working on linux, there is ^M at the end
of each line. What I want to do is to remove this character and separate
the string to an array. How can I do this?
Can I just check that I understand correctly. You have a string with
embedded ^M characters and you wish to turn this into an array of
strings? If that is correct then I would suggest looking at
String#split.
The ^M is a line feed shown in an editor such as vim because Linux
only needs a carriage return (\n)
You could do the following:
"one\r\ntwo\nthree\rfour".split(/[\n\r]+/) which will split the string
into "lines" at every combinations of carriage return and/or line feed
Thanks. I think split is what I want.
Another thing is that how I can remove the ^M from a string. I found
that there is a method "replace" in string class. But it will replace
the whole string, right?