I'd go with Rob's suggestion - use a regex match. So your string can be: @text = "Your are registered as a Member, we will SMS you soon. Ref ID: 12345" # (or any number in place of 12345...) @refID = @text.match(/\d+/).to_s
@refID will then contain the number, returned as a string (you can convert it to_i if you need to do any math operations on it but I assume you don't). If you want to make the match more precise, and the number is always at the end of the sentence and after "Ref ID:", you could even do something like this: @refID = @text.match(/ID:\s\d+$).to_s.gsub(/ID:\s/, "") This will only match numbers after "ID: " and that are at the end of the string - it then removes the "ID: " part and you are again left with the number returned as a string. On Jan 29, 6:26 am, rob <rs...@verizon.net> wrote: > What about trying to use regex? > > Use some regex to find 'Ref ID: ', then grab only the digits that > follow. I'll try to give you a code example but don't have the time > at the moment. Hope this helps get you started at least. > > On Jan 28, 9:42 pm, vasu <br.vas...@gmail.com> wrote: > > > Ref ID will be changing randomly please let me know i can't hard code > > that part > > > On Jan 29, 10:32 am, sHiVa <krapa.ph...@gmail.com> wrote: > > > > Hi Vasu, use this code; > > > > #***************************************************** > > > > text="Ref ID: 12345" > > > num=text.split(":") > > > intnum=num[1].to_i > > > print intnum > > > > #***************************************************** > > > > I hope this will help u . :) > > > > On Jan 29, 9:56 am, vasu <br.vas...@gmail.com> wrote: > > > > > Hi, > > > > > Iam new to watir can anyone help me in this regard: > > > > > "Your are registered as a Member, we will SMS you soon. Ref ID: 12345 > > > > > I want to Pick that 12345 from the the above output. > > > > > Please helpme....- Hide quoted text - > > > - Show quoted text - --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---