Here's one way to do it: row_values = row.text.split(/\w+ /)
1.upto (row_values.length) do |number| puts "date#{number} = #{row_value[number - 1]}, month#{number}= #{row_value[number - 1]}, Year#{number}= #{row_value[number - 1]}, value#{number} = #{row_value[number - 1]}, Status#{number} = #{row_value[number - 1]} split divides a string where it encounters it's argument and returns an array of the elements of the string left over. I could have put a space " " inside the parentheses for split, but I couldn't see whether you had more than one space in that list of values. So I used a regular expression /\w+/ instead, which means "any whitespace at all, including tabs and newlines and such". Then we just count. We need to know the number of elements in the array, so we use "length". You wanted your text to start counting at one, but arrays are indexed by zero, so I have to slice the array with "number-1" for each time through the loop. BTW, this is a classic associative array, also known as a hash. A hash might be a better way to arrange this information. You could search google for "ruby array" and "ruby hash" for more information. On 1/15/07, VIKASH KUMAR <[EMAIL PROTECTED]> wrote:
I am running a test case, in which I want to store all the values of a table in variables, I am using the below code: require 'watir' ie=Watir::IE.start("C:\test.htm") class Test def test_row_collection(ie) t= ie.table(:class,'listView') value_i = 0 t.rows.each do |row| puts row puts "Our Number is " && value_i value_i += 1 end end end TestObj = Test.new TestObj.test_row_collection(ie) It displays the following output: type: id: name: value: disabled: false 0 type: id: name: value: disabled: false 1 type: id: name: value: disabled: false If I used "puts row.text" in the above definition, it displays the following output. 0 01/14/2007 Jan/2007 2007 13 Open 1 01/15/2007 Jan/2007 2007 16 Open I want to store values like this: date1 = 01/14/2007, month1= Jan/2007, Year1= 2007, value1 = 13, Status1 = Open date2 = 01/14/2007, month2= Jan/2007, Year2= 2007, value2 = 16, Status2 = Open Please help me out in doing this. Thanks in advance Vikash ------------------------------ Here's a new way to find what you're looking for - Yahoo! Answers<http://us.rd.yahoo.com/mail/in/yanswers/*http://in.answers.yahoo.com/> _______________________________________________ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
_______________________________________________ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general