views:

414

answers:

4

Can anyone point to best algorithm for substring search in another string? or search for a char array in another char array?

+8  A: 

The best from what point of view? Knuth-Morris-Pratt is a good one. You can find more of them discussed on the Wikipedia entry for string searching algorithms.

Mehrdad Afshari
+3  A: 

It depends on what types of searching you are doing. Specific substring over a specific string? Specific substring over many different strings? Many different substrings over a specific string?

Here's a popular algorithm for a specific substring over many different strings.

John Calsbeek
A: 

This strstr() implementation seems pretty slick.

chaos
It is strstr.c for alpha. Which algorithm it uses? Which algorithm is used in x86 (or _64) for strstr?
osgx
A: 

Boyer-Moore algorithm: http://en.wikipedia.org/wiki/Boyer–Moore_string_search_algorithm

RBarryYoung