[Wtr-general] A doubt

Željko Filipin zeljko.filipin at gmail.com
Thu Mar 1 06:00:17 EST 2007


You can do it using regular expressions. ie.text will get all text in
browser. I guess there is a space after "Time" and before "milisec" and that
there is some text before and after it.

ie.text
=> "text Time 1234 millisec text"

Put "Time 1234 millisec" in variable ms. "." means any character, "*" means
as many characters as there is.

ms = ie.text.match /Time .* millisec/
ms  = ms.to_s
=> "Time 1234 millisec"

Delete "Time " and " millisec" from ms.

ms  = ms.sub("Time ", "")
=> "1234 millisec"

ms  = ms.sub(" millisec", "")
=> "1234"

Now ms variable contains only number of milliseconds.

ms
=> "1234"

For more information see http://www.regular-expressions.info/ruby.html
and http://www.rubycentral.com/book/tut_stdtypes.html
(section Regular Expressions)

There is surely a quicker way to do it, but this also works.
-- 
Zeljko Filipin
zeljkofilipin.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/wtr-general/attachments/20070301/8e553b3a/attachment.html 


More information about the Wtr-general mailing list