Search

Searches a keyword in the document.

public IEnumerable<SearchResult> Search(string keyword)
Parameter Type Description
keyword String The keyword to search.

Return Value

A collection of SearchResult objects; null if search isn’t supported.

Remarks

Learn more:

Examples

The following example shows how to find a keyword in a document:

// Create an instance of Parser class
using(Parser parser = new Parser(filePath))
{
    // Search a keyword:
    IEnumerable<SearchResult> sr = parser.Search("page number");
    // Check if search is supported
    if(sr == null)
    {
        Console.WriteLine("Search isn't supported");
        return;
    }
 
    // Iterate over search results
    foreach(SearchResult s in sr)
    {
        // Print an index and found text:
        Console.WriteLine(string.Format("At {0}: {1}", s.Position, s.Text));
    }
}

See Also


Search(string, SearchOptions)

Searches a keyword in the document using search options (regular expression, match case, etc.).

public IEnumerable<SearchResult> Search(string keyword, SearchOptions options)
Parameter Type Description
keyword String The keyword to search.
options SearchOptions The search options.

Return Value

A collection of SearchResult objects; null if search isn’t supported.

Remarks

Learn more:

Examples

The following example shows how to search with a regular expression in a document:

// Create an instance of Parser class
using(Parser parser = new Parser(filePath))
{
    // Search with a regular expression with case matching
    IEnumerable<SearchResult> sr = parser.Search("page number: [0-9]+", new SearchOptions(true, false, true));
    // Check if search is supported
    if(sr == null)
    {
        Console.WriteLine("Search isn't supported");
        return;
    }
 
    // Iterate over search results
    foreach(SearchResult s in sr)
    {
        // Print an index and found text:
        Console.WriteLine(string.Format("At {0}: {1}", s.Position, s.Text));
    }
}

The following example shows how to search a text on pages:

// Create an instance of Parser class
using(Parser parser = new Parser(filePath))
{
    // Search a keyword with page numbers
    IEnumerable<SearchResult> sr = parser.Search("line", new SearchOptions(false, false, false, true));
    // Check if search is supported
    if(sr == null)
    {
        Console.WriteLine("Search isn't supported");
        return;
    }
 
    // Iterate over search results
    foreach(SearchResult s in sr)
    {
        // Print an index, page number and found text:
        Console.WriteLine(string.Format("At {0} (page {1}): {2}", s.Position, s.PageIndex, s.Text));
    }
}

See Also