Skip to content

Instantly share code, notes, and snippets.

@onewland
Forked from rachelmyers/strstr
Created December 6, 2010 16:27
Show Gist options
  • Save onewland/730523 to your computer and use it in GitHub Desktop.
Save onewland/730523 to your computer and use it in GitHub Desktop.
def substring(haystack, needle)
0.upto(haystack.length) do |i|
return i if haystack[i,(needle.length)] == needle
end
return nil
end
puts substring("stupid", "smart")
puts substring("stupid", "stu")
puts substring("stupid", "pid")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment