ParserSearch Method (String, SearchOptions) |
Namespace: GroupDocs.Parser
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)); } }