[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

fastest way to remove this strange character

Junkone

12/26/2007 6:19:00 PM

Hello
I was trying out the roo gem and encountered this issue. when i do a
object.sheets, it seems to spit out the array and adds \000 for every
letter of the sheet name
for eg.
currentTrade becomes c\000u\000r\000r\000e\000n\000t\000T\000r\000a
\000d\000e\000

which is the fastest way to remove \000 from the array.



irb(main):005:0> ss=Excel.new("E:\\Documents and Settings\\TTSSR0149\Desktop\\orderingsystem.xls")

irb(main):003:0> ss.sheets()
=> ["c\000u\000r\000r\000e\000n\000t\000T\000r\000a\000d\000e\000", "M
\000i\000s
\000s\000e\000d\000T\000r\000a\000d\000e\000", "S\000c\000a\000n\000s
\000", "c\0
00l\000o\000s\000e\000d\000"]
irb(main):004:0>
2 Answers

darren kirby

12/26/2007 6:36:00 PM

0

quoth the Junkone:
> Hello
> I was trying out the roo gem and encountered this issue. when i do a
> object.sheets, it seems to spit out the array and adds \000 for every
> letter of the sheet name
> for eg.
> currentTrade becomes c\000u\000r\000r\000e\000n\000t\000T\000r\000a
> \000d\000e\000
>
> which is the fastest way to remove \000 from the array.

irb> s = "c\000u\000r\000r\000e\000n\000t\000T\000r\000a\000d\000e\000"
irb> n = ""
irb> s.unpack("S*").each {|c| n << c.chr}
=> [99, 117, 114, 114, 101, 110, 116, 84, 114, 97, 100, 101]
irb> n
=> "currentTrade"

Not sure if this is fastest or 'best'...

-d
--
darren kirby :: Part of the problem since 1976 :: http://badco...
"...the number of UNIX installations has grown to 10, with more expected..."
- Dennis Ritchie and Ken Thompson, June 1972

Jano Svitok

12/26/2007 11:33:00 PM

0

On Dec 26, 2007 7:20 PM, Junkone <junkone1@gmail.com> wrote:
> Hello
> I was trying out the roo gem and encountered this issue. when i do a
> object.sheets, it seems to spit out the array and adds \000 for every
> letter of the sheet name
> for eg.
> currentTrade becomes c\000u\000r\000r\000e\000n\000t\000T\000r\000a
> \000d\000e\000
>
> which is the fastest way to remove \000 from the array.
>
>
>
> irb(main):005:0> ss=Excel.new("E:\\Documents and Settings\\TTSSR0149> \Desktop\\orderingsystem.xls")
>
> irb(main):003:0> ss.sheets()
> => ["c\000u\000r\000r\000e\000n\000t\000T\000r\000a\000d\000e\000", "M
> \000i\000s
> \000s\000e\000d\000T\000r\000a\000d\000e\000", "S\000c\000a\000n\000s
> \000", "c\0
> 00l\000o\000s\000e\000d\000"]
> irb(main):004:0>

It's unicode - so you may use iconv to convert to whatever 8-bit
encoding you want.
If you want to have the 'fastest' one - compare it to other approaches
with Benchmark.