hi all, I want to remove o, which is present in the before statement, like @a=EDIA00050 (in this EDIA is common) @t=@a.spilt("EDIA") render_text @t[1] so i will get the output like 000050, but i want 50 only, like this this record will be change 000150,001150 so i want to remove which is in front of the element ''o'' it should not remove ''0'', which is back, please let me know , how to do this. -- 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 11 Oct 2007, at 11:29, Vidya Vidya wrote:> > hi all, > > I want to remove o, which is present in the before statement, like > > @a=EDIA00050 (in this EDIA is common) > @t=@a.spilt("EDIA") > render_text @t[1] >a =~ /0*([1-9]\d*)/ puts $1 Fred>--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
hi Fred, thanks for your reply, but i don''t know how to apply in my coding, can you tell me Frederick Cheung wrote:> On 11 Oct 2007, at 11:29, Vidya Vidya wrote: > >> >> hi all, >> >> I want to remove o, which is present in the before statement, like >> >> @a=EDIA00050 (in this EDIA is common) >> @t=@a.spilt("EDIA") >> render_text @t[1] >> > a =~ /0*([1-9]\d*)/ > puts $1 > > Fred-- 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 -~----------~----~----~----~------~----~------~--~---
Vidya Vidya wrote:> hi all, > > I want to remove o, which is present in the before statement, like > > @a=EDIA00050 (in this EDIA is common) > @t=@a.spilt("EDIA") > render_text @t[1]gsub: http://www.ruby-doc.org/core/classes/String.html#M000832 @a=EDIA00050 (in this EDIA is common) # this will work given that the string always starts with EDIA and follows immediately with 0 or more zero''s. @t=@a.gsub(/^EDIA0*/, '''') render_text @t[1] i''d advise looking into regexp a little deeper if this seems odd to you. http://en.wikipedia.org/wiki/Regular_expression#Syntax hope it helps! shai -- 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 -~----------~----~----~----~------~----~------~--~---
Thank you so much shai, it works well -- 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 10/11/07, Shai Rosenfeld <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Vidya Vidya wrote: > > hi all, > > > > I want to remove o, which is present in the before statement, like > > > > @a=EDIA00050 (in this EDIA is common) > > @t=@a.spilt("EDIA") > > render_text @t[1] > > gsub: > http://www.ruby-doc.org/core/classes/String.html#M000832 > > @a=EDIA00050 (in this EDIA is common) > # this will work given that the string always starts with EDIA and > follows immediately with 0 or more zero''s. > @t=@a.gsub(/^EDIA0*/, '''') > render_text @t[1]And if you don''t need to save the value in an instance variable just: render_text @a.gsub(/^EDIA0*/, '''') I''ve got no idea what @a and @t represent, or whether they should really BE instance variables or locals. One strong suggestion to the OP is to use meaningful variable names. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.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 -~----------~----~----~----~------~----~------~--~---
Thanks for your suggestion, i try to use meaningful words -- 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 -~----------~----~----~----~------~----~------~--~---
Shai Rosenfeld wrote:> @t=@a.gsub(/^EDIA0*/, '''')gsub does the job, but match is designed to return parts of a string that "match": EDIA_ID = /[1-9]\d*$/ @t = @a.match(EDIA_ID)[0] =>"50" ...and can be used to get multiple matches at a time, which is sometimes useful (though probably not in this case): EDIA_PARTS = /^(.*)([1-9]\d*)$/ all, prefix, edia_id = a.match(EDIA_PARTS).captures => ["EDIA00050", "EDIA000", "50"] edia_id => "50" match returns a MatchData object whose "matches" can be accessed with the [] method -- like an array (though you have to use captures or to_a to actually get an array). [0] returns the entire data matched, and [1]+ return the parenthetical submatches (like a regular expression replace string with \1 or $1 backreferenced subpatterns). The MatchData object also retains information about where the matches were found in the original string which can be accessed later with various 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-/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 -~----------~----~----~----~------~----~------~--~---
hi vidya, I think, simply u can also use like below for this scenario: "@t[1].to_i" this will return the integer value right i.e 50 Regards, P.Gokula murthy On 10/11/07, Vidya Vidya <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > hi all, > > I want to remove o, which is present in the before statement, like > > @a=EDIA00050 (in this EDIA is common) > @t=@a.spilt("EDIA") > render_text @t[1] > > so i will get the output like 000050, but i want 50 only, like this > this record will be change 000150,001150 so i want to remove which is in > front of the element ''o'' it should not remove ''0'', which is back, please > let me know , how to do this. > -- > 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 -~----------~----~----~----~------~----~------~--~---