/ Published in: Ruby

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
Example:
# get_string_between("hellomyfriendmoto", 'o', 'm')
# > myfriend
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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
Comments
