Declaration
Automation:
ulong  Find ( [in]   ref byte  pDataToFind, [in]   uint  data_size, [in]   IMultiSelection  pSelection, [in]   ulong  StartFrom, [in]   bool  search_up, [in]   bool  ignore_case) ;
Native (C++):
HRESULT  Find ( [in]   unsigned char *  pDataToFind, [in]   unsigned long  data_size, [in]   IMultiSelection *  pSelection, [in]   unsigned __int64  StartFrom, [in]   VARIANT_BOOL  search_up, [in]   VARIANT_BOOL  ignore_case, [out, retval]   unsigned __int64 *  offset_found) ;
Parameters
pDataToFindPointer to a patterndata_sizePattern sizepSelectionMultiple selection object, which contains ranges in which you want to locate a patternStartFromOffset from which you want to start searchingsearch_upTrue to search backwards and False to search forwardignore_caseTrue to ignore case and False to perform exact matchingoffset_foundPointer to a variable that receives the located pattern offset or -1 if pattern was not found.
Return Value
Automation:Offset of the located pattern or -1 if pattern was not foundNative: S_OK or standard OLE error code.
Remarks
Searches for a pattern within a given selection. This method returns the offset of the matched pattern. To continue searching, call this method again, adjusting StartFrom field appropriately. If pattern is not found in the specified range, -1 is returned. Complexity: linear-time, depending on the file's size and selection's complexity.
Examples

Searching for a pattern

C#Copy Code
FileDocumentLib.FileDocument fdoc = new FileDocumentLib.FileDocument();
FileDocumentLib.IMultiSelection msec = fdoc.CreateEmptySelection();

fdoc.Open(@"c:\temp\file.txt");
msec.AddRange(0, fdoc.FileSize);  // We'll be searching in a whole file

byte[] pattern = new byte[] { 0x0d, 0x0a }; // EOL pattern
ulong EOL_Offset = fdoc.Find(ref pattern[0], pattern.Length, msel, 0, false, false);
// ...
// continue searching
EOL_Offset = fdoc.Find(ref pattern[0], pattern.Length, msel, EOL_Offset + 1, false, false);