hello.... if i have a string ''12-34-56-78'', how can i replace the ''78'' with ''91''...pls.....help... 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-/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 -~----------~----~----~----~------~----~------~--~---
string = ''12-34-56-78'' string.gsub(((string.reverse.match /(.*?)-.*/)[1].reverse), ''love'') Warning: unnecessarily complicated maybe, but works. :-) Later, Vish On 8/9/07, Monet Belleza <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > hello.... > > if i have a string ''12-34-56-78'', how can i replace the ''78'' with > ''91''...pls.....help... > > > > > > 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-/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 8/9/07, Monet Belleza <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > hello.... > > if i have a string ''12-34-56-78'', how can i replace the ''78'' with > ''91''...pls.....help...''12-34-56-78''[-2,2] = "91" HTH Daniel --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Vishnu Gopal wrote:> string = ''12-34-56-78'' > > string.gsub(((string.reverse.match /(.*?)-.*/)[1].reverse), ''love'') > > Warning: unnecessarily complicated maybe, but works. :-) > > Later, > VishThanks..a lot..it works............... Your my angel in disguise.. -- 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 -~----------~----~----~----~------~----~------~--~---
Monet Belleza wrote:> Vishnu Gopal wrote: >> string = ''12-34-56-78'' >> >> string.gsub(((string.reverse.match /(.*?)-.*/)[1].reverse), ''love'') >> >> Warning: unnecessarily complicated maybe, but works. :-) >> >> Later, >> Vish > > > > Thanks..a lot..it works............... > Your my angel in disguise..Hi..Vish.. I have a question..what if the string is ''12-34-56-56''..and i only want to change the last substr.. it results to ''12-34-love-love''. pls..help 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-/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 -~----------~----~----~----~------~----~------~--~---
mmm Looks like my post was lost to the ether ''12-34-56-78''[-2,2] = "91" HTH Daniel On 8/9/07, Monet Belleza <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Monet Belleza wrote: > > Vishnu Gopal wrote: > >> string = ''12-34-56-78'' > >> > >> string.gsub(((string.reverse.match /(.*?)-.*/)[1].reverse), ''love'') > >> > >> Warning: unnecessarily complicated maybe, but works. :-) > >> > >> Later, > >> Vish > > > > > > > > Thanks..a lot..it works............... > > Your my angel in disguise.. > > > Hi..Vish.. > > I have a question..what if the string is ''12-34-56-56''..and i only > want to change the last substr.. > > it results to ''12-34-love-love''. > > pls..help > > 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-/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 -~----------~----~----~----~------~----~------~--~---
Daniel ----- wrote:> mmm Looks like my post was lost to the ether > > ''12-34-56-78''[-2,2] = "91" > > HTH > Danielhi..daniel Its just that the last substr ''78'' will be replaced with another string.. like ''12-34-56-91''... last_str = ''856'' string = ''123-456-123'' the result string should be ... string = ''123-456-856'' how.??? pls help.. 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-/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 8/9/07, Monet Belleza <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Daniel ----- wrote: > > mmm Looks like my post was lost to the ether > > > > ''12-34-56-78''[-2,2] = "91" > > > > HTH > > Daniel > > > > hi..daniel > > Its just that the last substr ''78'' will be replaced with another > string.. > > like ''12-34-56-91''... > > last_str = ''856'' > string = ''123-456-123'' > the result string should be ... > string = ''123-456-856'' > > how.??? > pls help.. > > > thanksSorry I misunderstood. "123-456-856".sub( /\d+$/, "999" ) "123-456-999" /\d+$/ Matches the last numeric digits in the string, since it''s anchored to the end of the string, and replaces them with the second argument. HTH Daniel --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Daniel ----- wrote:> On 8/9/07, Monet Belleza <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> >> the result string should be ... >> string = ''123-456-856'' >> >> how.??? >> pls help.. >> >> >> thanks > > > Sorry I misunderstood. > > "123-456-856".sub( /\d+$/, "999" ) > "123-456-999" > > /\d+$/ Matches the last numeric digits in the string, since it''s > anchored to > the end of the string, and replaces them with the second argument. > > HTH > DanielIt works.. Thank you so much.................... God bless... -- 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 -~----------~----~----~----~------~----~------~--~---
Daniel: that''s cool, didn''t think of that :-) Vish On 8/9/07, Daniel N <has.sox-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On 8/9/07, Monet Belleza <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > > > Daniel ----- wrote: > > > mmm Looks like my post was lost to the ether > > > > > > ''12-34-56-78''[-2,2] = "91" > > > > > > HTH > > > Daniel > > > > > > > > hi..daniel > > > > Its just that the last substr ''78'' will be replaced with another > > string.. > > > > like ''12-34-56-91''... > > > > last_str = ''856'' > > string = ''123-456-123'' > > the result string should be ... > > string = ''123-456-856'' > > > > how.??? > > pls help.. > > > > > > thanks > > Sorry I misunderstood. > > "123-456-856".sub( /\d+$/, "999" ) > "123-456-999" > > /\d+$/ Matches the last numeric digits in the string, since it''s anchored to > the end of the string, and replaces them with the second argument. > > HTH > Daniel > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---