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?

有帮助吗?

解决方案

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!
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top