Let us say that I have this string:
bar="hello kohello hello"
I would like a function foo that I give it
foo(bar,"hello")
And get:
[0,8,14]
Now, I could just do (1 of many options):
def foo(str1,substr)
i= -1
substr_length = substr.length()
str1.chars.map{ | char |
i+=1
str1(i,substr_length) == substr ? i : nil
}.select{ |x| x }
end
Is there something more "Ruby like"? Also with Regexp, rather than strings.
Thanks.