| Example Program Exact Searching Exact string matching. File "find_exact.cpp" A tutorial about the use of exact find algorithms.
1 | #include <iostream>
2 | #include <seqan/find.h>
3 |
4 | using namespace seqan;
5 |
This function prints the positions of all occurrences of needle within haystack. It uses the algorithm specified by TAlgorithm that is passed as a Specialization to Pattern.
6 | template <typename TAlgorithm>
7 | void printAllOccs(String<char>& haystack,
8 | String<char>& needle)
9 | {
10 | Finder<String<char> > finder(haystack);
11 | Pattern<String<char>, TAlgorithm> pattern(needle);
12 | while (find(finder, pattern))
13 | {
14 | ::std::cout << position(finder) << ", ";
15 | }
16 | ::std::cout << ::std::endl;
17 | }
18 |
The main function calls printAllOccs for different exact string matching algorithms.
19 | int main()
20 | {
21 | String<char> haystack = "send more money!";
22 | String<char> needle = "mo";
23 |
24 | printAllOccs<Horspool>(haystack, needle);
25 | printAllOccs<BomAlgo> (haystack, needle);
26 | printAllOccs<BndmAlgo>(haystack, needle);
27 | printAllOccs<ShiftAnd>(haystack, needle);
28 | printAllOccs<ShiftOr> (haystack, needle);
29 |
30 | return 0;
31 | }
32 |
See Also Searching SeqAn - Sequence Analysis Library - www.seqan.de