Example A: "Example One" What I need is a string method to remove " One" from that string so the result is just "Example". I''m sure this is very simple but I just require a swift response. Thanks. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Thu, Jan 7, 2010 at 10:10 AM, Pale Horse <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Example A: "Example One" > > What I need is a string method to remove " One" from that string so the > result is just "Example". > > I''m sure this is very simple but I just require a swift response.How about "Example One".split? --wpd -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Pale Horse wrote:> Example A: "Example One" > > What I need is a string method to remove " One" from that string so the > result is just "Example". > > I''m sure this is very simple but I just require a swift response. > > Thanks.a = "Example One" a = a.split(/ /)[0] In general, the way to solve a problem is to try and tackle it from different angles. Do you want to ... a) remove everything after ''Example''? b) remove the last four characters of the string? c) remove everything after the first word? d) remove the last word and the last space? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> a = "Example One" > a = a.split(/ /)[0] > > In general, the way to solve a problem is to try and tackle it from > different angles. > Do you want to ... > a) remove everything after ''Example''? > b) remove the last four characters of the string? > c) remove everything after the first word? > d) remove the last word and the last space?I want to remove everything after the first word. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Quoting Pale Horse <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>:> Example A: "Example One" > > What I need is a string method to remove " One" from that string so the > result is just "Example". >irb(main):010:0> "Example One and trailing stufff".split('' '', 2)[0] => "Example" irb(main):014:0> "Example One and trailing stuff".slice(/\w+/) => "Example" HTH, Jeffrey -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Pale Horse wrote:>> a = "Example One" >> a = a.split(/ /)[0] >> >> In general, the way to solve a problem is to try and tackle it from >> different angles. >> Do you want to ... >> a) remove everything after ''Example''? >> b) remove the last four characters of the string? >> c) remove everything after the first word? >> d) remove the last word and the last space? > > I want to remove everything after the first word.Well, then my solution works for you, but you should familiarize yourself with it. http://ruby-doc.org/core/ Go check out the String methods. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.