Skip to content

Converting string to arrays tip

March 16, 2011

Converting string to arrays (using a command like split) can be a useful thing to do various operations.

I currently used it to manipulate a string that held a path:

ruby-1.9.2-p136 :004 > arr = "/media/audio/2000/20000520_excerpt.mp3".split(/\//) 
=> ["", "media", "audio", "2000", "20000520_excerpt.mp3"] 
ruby-1.9.2-p136 :005 > new_arr = arr[arr.index("audio")...arr.count] 
=> ["audio", "2000", "20000520_excerpt.mp3"]
Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: