FFindString Function

Action

Searches for the first occurrence of the specified string and, if found, sets the current position of the file pointer to the first character of the found string.

Include file

Kernel.bdh

Syntax

FFindString( in hFile      :number;
             in sSearchStr : string ): boolean;

Return value

  • true if the string was found

  • false otherwise

Parameter Description
hFile Valid handle to an open file. This handle must have been returned from a previous call to FOpen.
sSearchStr String to search for

Example

dcltrans
  transaction TMain
  const
    scFileName := "c:\\temp\\dummyfile.txt";
  var
    hFile            : number;
    sOutput, sSearch : string;
  begin
    // create a file and store a string
    FOpen(hFile, scFileName, OPT_FILE_ACCESS_READWRITE, OPT_FILE_CREATE);
    sOutput := "Hope the weather will be fine tomorrow!";
    FWrite(hFile, sOutput);
    FClose(hFile);
    write("new file created"); writeln;

    // search for the word "weather" in the file
    FOpen(hFile, scFileName);
    sSearch := "weather";
    if FFindString(hFile, sSearch) then
      write("word found"); writeln;
    else
      write("word not found"); writeln;
    end;

    // close file
    FClose(hFile);
    write("file closed");
    writeln;
  end TMain;

Output

new file created
word found
file closed