Revision: 63278
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at April 22, 2013 06:50 by joshmn
Initial Code
def get_string_between(my_string, start_at, end_at)
my_string = " #{my_string}"
ini = my_string.index(start_at)
return my_string if ini == 0
ini += start_at.length
length = my_string.index(end_at, ini).to_i - ini
my_string[ini,length]
end
Initial URL
Initial Description
If you're using Rails and want to make this a global function, drop this into your application_controller and call it as a function.
Example:
# get_string_between("hellomyfriendmoto", 'o', 'm')
# > myfriend
Initial Title
Get string between two strings
Initial Tags
rails, ruby
Initial Language
Ruby