FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.

» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Ubuntu > Ubuntu User

LinkBack Thread Tools
Old 12-05-2010, 05:22 PM
Colin Law
Default Strange problem with CSV and funny chars

I am using CSV in a rake task (db:seed) on Rails 3.0.3, Ruby 1.9.2 to
read a file with some funny chars in it. Upon breaking in at a point
where the row read using CSV is in variable row, with the string with
the char in row['price'] I get the following strange results which I
cannot understand.

(rdb:1) row['price']
(rdb:1) row['price'][0]
(rdb:1) row['price'][0] == "xA3"
(rdb:1) row['price'][0].each_byte{|c| print c, ' '}
163 "xA3"
(rdb:1) "xA3".each_byte{|c| print c, ' '}
163 "xA3"
(rdb:1) "xA3".class
(rdb:1) row['price'][0].class
(rdb:1) row['price'][0] <=> "xA3"
(rdb:1) "xA3" <=> row['price'][0]
(rdb:1) row['price'][0].length
(rdb:1) "xA3".length

So it appears that "xA3" and row['price'][0] are both strings of
length 1 and both contain the byte value 163 yet "xA3" is definitely
greater than row['price'][0]
If I do c1 = row['price'][0] and c2 = "xA3" I still get the same
effect. The variables c1 and c2 contain the same data but are
different when compared.

No doubt I am doing something stupid, if someone could point out what,
then I would be most grateful.


ubuntu-users mailing list
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users

Thread Tools

All times are GMT. The time now is 04:02 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org