Ok I know that sounds newbish, but I don''t want to match the entire string. I just want to match the first 25 characters or so. I have a hash that looks like somestuff[:something] Now I want somestuff[:something] to equal a string. somestuff[:something] == ''sadfasdfsdfasdf'' the problem is that somestuff[:something] will never match the entire string, so I want to match the first 25 characters. Any ideas...I hope that made sense? -- 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 -~----------~----~----~----~------~----~------~--~---
On Mar 17, 2009, at 3:24 PM, Chris Gunnels wrote:> > Ok I know that sounds newbish, but I don''t want to match the entire > string. I just want to match the first 25 characters or so. > > I have a hash that looks like > > somestuff[:something] > > Now I want somestuff[:something] to equal a string. > > somestuff[:something] == ''sadfasdfsdfasdf'' > > the problem is that somestuff[:something] will never match the entire > string, so I want to match the first 25 characters. > > Any ideas...I hope that made sense?somestuff[:something][0,25] = "asdfasdfasdf" Is one way. There''s probably a ruby method to match N characters of a string similar to C''s strncmp too. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Chris Gunnels wrote:> Ok I know that sounds newbish, but I don''t want to match the entire > string. I just want to match the first 25 characters or so. > > I have a hash that looks like > > somestuff[:something] > > Now I want somestuff[:something] to equal a string. > > somestuff[:something] == ''sadfasdfsdfasdf'' > > the problem is that somestuff[:something] will never match the entire > string, so I want to match the first 25 characters. > > Any ideas...I hope that made sense?There are a number of ways depending on your needs. In your case if you just want to match the beginning of the string Rails provides the starts_with method (Ruby 1.9 provides start_with, but not Ruby 1.8). For more complex matches Ruby has excellent regex support. Look at the ~= method. somestuff[:something].starts_with "whatever" somestuff[:something] ~= /^whatever.+/i -- 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 -~----------~----~----~----~------~----~------~--~---
Robert Walker wrote:> just want to match the beginning of the string Rails provides the > starts_with method (Ruby 1.9 provides start_with, but not Ruby 1.8). For > more complex matches Ruby has excellent regex support. Look at the ~= > method. > > somestuff[:something].starts_with "whatever"Thanks for the info... Can "whatever" be a variable? -- 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 -~----------~----~----~----~------~----~------~--~---