Fast String Searching With Suffix Trees
marknelson.us
Summary: Building a Suffix Tree (in O(n) time and space) allows you to search for substrings in O(m) time (m being size of substring).
Link is to article describing algorithm and giving sample code in C++.