Satish
Satish

Reputation: 6485

substring algorithm

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

Upvotes: 6

Views: 5481

Answers (4)

RBarryYoung
RBarryYoung

Reputation: 56725

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

Upvotes: 1

John Calsbeek
John Calsbeek

Reputation: 36497

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.

Upvotes: 3

chaos
chaos

Reputation: 124257

This strstr() implementation seems pretty slick.

Upvotes: 0

Mehrdad Afshari
Mehrdad Afshari

Reputation: 421968

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.

Upvotes: 8

Related Questions