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? thanks. -- Posted via http://www.ruby-forum.com/.
On Thu, Jul 9, 2009 at 7:49 PM, Zhao Yi <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>wrote:> > 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? > > thanks.You can try using dos2unix or others methods located here: http://aruljohn.com/info/ctrlm/ Good luck, -Conrad> > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
2009/7/10 Zhao Yi <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > 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. Colin
On Fri, Jul 10, 2009 at 1:22 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> > 2009/7/10 Zhao Yi <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>: > > > > 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. >Colin, he wants to first remove the ^M from the string. Then he wants to split the string. -Conrad --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Sat, Jul 11, 2009 at 12:42 AM, Conrad Taylor<conradwt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Fri, Jul 10, 2009 at 1:22 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> >> 2009/7/10 Zhao Yi <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>: >> > >> > 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. > > Colin, he wants to first remove the ^M from the string. Then he wants to > split > the string. > -ConradThe ^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 Andrew Timberlake http://ramblingsonrails.com http://MyMvelope.com - The SIMPLE way to manage your savings
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? -- Posted via http://www.ruby-forum.com/.
2009/7/16 Zhao Yi <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > 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? > --Have a look at the gsub method of String Colin