From: Robert Schaaf Date: 2009-07-23T23:40:15+09:00 Subject: Re: splitting............. --Apple-Mail-1--530134232 Content-Type: text/plain; charset=WINDOWS-1252; format=flowed; delsp=yes Content-Transfer-Encoding: quoted-printable But what if your addressee is Samuel Barber at Capricorn, Mt. Kisko, =20 NY. Or in the Brill Building at 1619 Broadway, Suite 511, New York, =20 NY? Or a law firm such as Miller, Mertens & Comfort, P.L.L.C. ? Excel will export these as Samuel Barber,"Capricorn, Mt. Kisco",NY Tin Pan Alley,"1619 Broadway, Suite 511", New York, NY "Miller, Mertens & Comfort, P.L.L.C.","1020 North Center Parkway, =20 Suite B",Kennenwick,WA Other systems might escape internal commas. Worse, grabbing rows from =20= a database and injecting commas between them, will lead to unparsable =20= results. There is no easy solution to this problem; you really have to parse on =20= well-formed input. Bob Schaaf On Jul 23, 2009, at 8:17 AM, Mirko Viviani wrote: > something similar... > > fi =3D File.open("yourfile", "r") > > #get key values > header =3D fi.gets.chomp.split(",") > allValues =3D [] > > while (!fi.eof) > values =3D fi.gets.chomp.split(",") > allValues << header.zip(values) > end > > fi.close > > puts allValues.inspect > > > > > > 2009/7/23 Hunt Hunt > >> Hi Friends, >> >> I have a file which information.txt which is like >> >> name,address,city,contact >> abc,Newyork,HYU,345 >> xyz,Pittsurg,UYY,234 >> >> >> only theree line. >> >> Now I have to split name, address,city & contact with their =20 >> associated >> values. >> >> how am i supposed to do this? >> >> Thanks for the information in advance. >> >> Regards >> HUNT/RUDIN >> -- >> Posted via http://www.ruby-forum.com/. >> >> > > > --=20 > -- Mirko Viviani -- > GPG-PGP Public Key: 0xE4E8FAB1 > Fingerprint: 14D3 A373 E926 7737 DF32 502B A4C4 1CE2 E4E8 FAB1 > *********************************************** > "=93Machines take me by surprise with great frequency.=94 A. Turing --Apple-Mail-1--530134232--