Domanda

I have the following array:

info = ["Thursday, July 19, 2012", 
        " \n    4:00 PM to 6:00 PM (CT) \n                  happy hour with company\n                  company100 W. Main St.Suite 5Chicago, IL 60602"]

I'm trying to convert info[1] from a single element into multiple elements in the info array. For instance, I'd like to divide info[1] into three elements (hours, event name/description, and address). Any idea how to begin doing this?

È stato utile?

Soluzione

How about

parts = info[1].split("\n").map(&:strip).reject(&:empty?)

If you want to put it back in, you could do something like

info[1] = parts
info.flatten!
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top