From: "Berger, Daniel" Date: 2006-08-31T23:54:39+09:00 Subject: Re: splitting string to hash > -----Original Message----- > From: list-bounce@example.com > [mailto:list-bounce@example.com] On Behalf Of Brian Nice > Sent: Thursday, August 31, 2006 8:39 AM > To: ruby-talk ML > Subject: splitting string to hash > > > I have a strings like the following: > s1- "[1] Hello [2] bye" > s2- "[1] Hello [2] bye [2:1] continue [2] more" Should that be "[2:2] more" ? > I want to convert them to hashes like > h1- {1 => "Hello", 2 => "bye"} arr = s1.split(/\s*?\[(.*?)\]\s*/) arr.delete("") h1 = Hash[*arr] I'm not actually sure why I get an empty string from the Array#split call. If someone can figure that out, you can get rid of the Array#delete call. Regards, Dan This communication is the property of Qwest and may contain confidential or privileged information. Unauthorized use of this communication is strictly prohibited and may be unlawful. If you have received this communication in error, please immediately notify the sender by reply e-mail and destroy all copies of the communication and any attachments.