From: Brian Nice Date: 2006-09-01T00:15:05+09:00 Subject: Re: splitting string to hash No, that was actually correct, the second one is [2] not [2:2]. The key would need to be 2:2 though otherwise it could possibly override another key. Thanks for the other one! Berger, Daniel wrote: >> 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 -- Posted via http://www.ruby-forum.com/.