[wtr-general] Re: How to get numbers from String?
Hi Željko, Thanks for your instant reply. I got some a handy solution by googling. str = Showing 1 to 10 of 72 Records total_number_of_records = str.scan(/\d+/)[2].to_i Again thanks, Prince3105 On Feb 19, 3:36 pm, Željko Filipin zeljko.fili...@wa-research.ch wrote: On Fri, Feb 19, 2010 at 11:22 AM, Prince3105 prince3...@gmail.com wrote: Its a ruby question. sorry for this. I want to get the value 72 from below string. Showing 1 to 10 of 72 Records Ruby questions are welcome here. Although, you could get better answers at ruby list. This is one way. Let me know if you do not understand it. $ irb Showing 1 to 10 of 72 Records.split( ) = [Showing, 1, to, 10, of, 72, Records] Showing 1 to 10 of 72 Records.split( )[5] = 72 Showing 1 to 10 of 72 Records.split( )[5].to_i = 72 More information: http://ruby-doc.org/core/classes/String.html Željko -- watir.com - community manager pledgie.com/campaigns/2982 - donate to Watir watirpodcast.com - host testingpodcast.com - podcasts on software testing. all of them -- You received this message because you are subscribed to the Google Groups Watir General group. To post to this group, send email to watir-general@googlegroups.com Before posting, please read the following guidelines: http://wiki.openqa.org/display/WTR/Support To unsubscribe from this group, send email to watir-general+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/watir-general
RE: [wtr-general] Re: How to get numbers from String?
irb(main):070:0 a = 'Showing 1 to 10 of 72 Records' = Showing 1 to 10 of 72 Records irb(main):071:0 a[/(\d+)\sto\s(\d+)\sof\s(\d+)/, 3] = 72 I couldn't resist sharing this. No disrespect to the other posters but I learned this trick from James Gray recently and think it's a really good trick. This works since you can use a regexp in brackets to index a string. You could also use: a[/(\d+)\sto\s(\d+)\sof\s(\d+)/, 1] or a[/(\d+)\sto\s(\d+)\sof\s(\d+)/, 2] ...to get the other numbers. Alan This email message and any attachments are for the sole use of the intended recipients and may contain proprietary and/or confidential information which may be privileged or otherwise protected from disclosure. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not an intended recipient, please contact the sender by reply email and destroy the original message and any copies of the message as well as any attachments to the original message. -- You received this message because you are subscribed to the Google Groups Watir General group. To post to this group, send email to watir-general@googlegroups.com Before posting, please read the following guidelines: http://wiki.openqa.org/display/WTR/Support To unsubscribe from this group, send email to watir-general+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/watir-general