views:

60

answers:

1

What is the most efficient way to do this? There must be some better method other than brute force.

+6  A: 

Depends on length of string, size of alphabet and whether repeated searching: Knuth-Morris-Pratt, Rabin-Karp, etc.

See String searching algorithm

Knuth-Morris-Pratt algorithm

Rabin-Karp algorithm

Mitch Wheat