The simplest option is to use the prefix function
(the algorithm of Knuth-Morris-Pratt). Then the search will be quite slow on large texts, but simple to implement.
You can use suffix array
, then the text search will be significantly faster, but will require each time you change the text to reconstruct the suffix array. The option for optimization is to build it only if you are requesting the search, and subsequent search queries(without changing the text) to use the already constructed suffix array.