FindText


The FindText method searches file for specified text encoded as single byte characters and returns position of matching data in file.
C++
long FindText(
  LPSTR TextData,                     // buffer containing searched data
  long NumberOfCharacters = -1,       // number of characters in data sequence
  long StartingPosition = 0,          // starting position of search
  long Range = -1,                    // search range
  long Options = 0                    // search options
);
long FindText(
  LPWSTR TextData,                    // buffer containing searched data
  long NumberOfCharacters = -1,       // number of characters in data sequence
  long StartingPosition = 0,          // starting position of search
  long Range = -1,                    // search range
  long Options = 0                    // search options
);
BASIC
FindText(
  TextData As Variant,                // variant containing searched data
  NumberOfCharacters As Long = -1,    // number of characters in data sequence
  StartingPosition As Long = 0,       // starting position of search
  Range As Long = -1,                 // search range
  Options As TextSearchOptions = 0    // search options
) As Long

Parameters

TextData
C++
Pointer to buffer containing character sequence to be searched for.
If parameter NumberOfCharacters is -1, sequence must be NULL terminated.
BASIC
Variant containing character sequence to be searched for.
Variant must be of String data type; it must not be an array.
NumberOfCharacters
Number of characters in data sequence to be matched.
If this parameter is -1 length of searched sequence is determined by the number of characters in TextData.
StartingPosition
Starting position of search in file.
If this parameter is -1 search begins at current file position.
If this parameter is 0 and Options have IXF_FIND_REVERSE flag set, search begins from the end of file.
Range
Length of file region to be searched, in bytes.
If this parameter is -1 search is continued until end of file or beginning of file depending on search direction.
Options
Search options, specified as a combination of the following values:
IXF_FIND_TEXT_REVERSE backward search (towards beginning of file),
IXF_FIND_TEXT_MATCHCASE case sensitive search,
IXF_FIND_TEXT_STRING raw character sequence search (see Remarks).

Return Values

If the method succeeds, the return value is the position of matching sequence in file.
The return value is IXF_FAILURE_NOTFOUND if specified data sequence has not been found.
If the method fails, the return value is failure code and error code is set. Call GetError to get error code.

Remarks

Data is searched in file starting from StartingPosition and continuing until matching sequence is found or search region has ended. File data must match entire sequence and must be positioned entirely within search region; it means that 'matching' sequence which starts within search region but ends beyond it is not recognized as matching.

StartingPosition always specifies absolute starting position in file regardless of direction of search. The only exception is when this parameter is 0 and Options have IXF_FIND_REVERSE flag set; in such situation search begins from the end of file.

IXFile represents text as length-prefixed by default. Actual text data in file is preceded with a long number specifying length of the text in characters. Text is searched for the same way - both text data and its length prefix must match, which means that you cannot search for a subpart of the text. If there is a need for searching subpart of a text (or text is stored in file as a raw character string without length prefix), IXF_FIND_TEXT_STRING flag should be set in Options parameter. When this option is enabled text is searched for as a raw sequence of characters ignoring length prefix and any matching sequence successfully finishes processing.

Unicode version of the method should not be confused with Unicode system calls or Unicode text data. All versions of the method can be used on Unicode and non-Unicode systems depending on your needs - text is always searched as a single byte character sequence. Conversion between Unicode and ANSI is performed internally according to current codepage which can be changed with SetCodePage method. See Unicode Support for more information on Unicode system calls, Unicode methods and Unicode text data.

See Also

FindUnicodeText, FindByte, FindShort, FindLong, FindFloat, FindDouble, FindVariant, FindBinary, Finding Data