problem with parsing string from excel file
Posted
by ohana
on Stack Overflow
See other posts from Stack Overflow
or by ohana
Published on 2010-05-14T00:30:33Z
Indexed on
2010/05/14
0:34 UTC
Read the original article
Hit count: 271
ruby-on-rails
hi,
i have ruby code to parse data in excel file using Parseexcel gem. I need to save 2 columns in that file into a Hash, here is my code:
worksheet.each { |row| if row != nil key = row.at(1).to_s.strip value = row.at(0).to_s.strip if !parts.has_key?(key) and key.length > 0 parts[key] = value end end }
however it still save duplicate keys into the hash: "020098-10". I checked the excel file at the specified row and found the difference are " 020098-10" and "020098-10". the first one has a leading space while the second doesn't. I dont' understand is it true that .strip function already remove all leading and trailing white space?
also when i tried to print out key.length, it gave me these weird number:
020098-10 length 18 020098-10 length 17
which should be 9....
© Stack Overflow or respective owner