Alex LeDonne
9/6/2006 2:36:00 PM
On 8/31/06, Brian Nice <bnice_99@yahoo.com> wrote:
> I have a strings like the following:
> s1- "[1] Hello [2] bye"
> s2- "[1] Hello [2] bye [2:1] continue [2] more"
>
> I want to convert them to hashes like
> h1- {1 => "Hello", 2 => "bye"}
> h2- {1 => "Hello", 2 => "bye", "2:1" => "continue", "2:2" => more"}
>
> Is there an easy Ruby way to do this?
Brian-
Your problem is somewhat underspecified; with more examples and info,
someone might be able to help better. Some important questions:
- may the phrases include spaces?
- can there be more than two levels?
- in your examples above, must the frist key be 1, or could it also be
"1"? Or perhaps "1:0"?
- perhaps some more background on the use case would help as well.
Good luck!
-Alex