0

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?

2
  • 3
    When asking a question on stackoverflow, you should be ready to answer the question: what have you tried? You should try to solve the problem yourself. Google the problem, read language reference, google more, write some code, read a good book, write more code. When you're officially stuck, then we'll be happy to help you. But you have to try first. Commented Jul 22, 2012 at 20:36
  • Thanks for the heads-up. I tried for about an hour using methods on Ruby-Doc as well as Google and several stackoverflow questions but couldn't find anything similar. In the future I'll include the steps I already tried (unsuccessfully) in my questions. Commented Jul 22, 2012 at 21:28

1 Answer 1

2

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!
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.