Skip to content

Instantly share code, notes, and snippets.

@levicole
Created February 7, 2013 23:41
Show Gist options
  • Save levicole/4735285 to your computer and use it in GitHub Desktop.
Save levicole/4735285 to your computer and use it in GitHub Desktop.
strstr
def strstr(subject, search)
si = 0
subject.length.times do |i|
if subject[i] == search[si]
if search.length == si + 1
@found_at = i - si
break
end
si += 1
else
si = 0
end
end
puts @found_at
end
strstr("hello there", "her")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment