Sometimes you need to find a string in the stream, which may be a half part of the ASCII table or mixed. But the routine provided online is poor and the code is lengthy.
Later, I wrote one time, the code is very small, the efficiency is very high. Only for reference:
Function ScanStream (T: TSTREAM; S: String): Integer; Var i, J: Integer; P: Pchar; Begin getMem (p, t.size); // Assign Memory T. Readbuffer (p ^, t.size) ;//read
For i: = 0 to t.size -1 do begin for j: = 1 to length (s) do if p [i j] <> s [j] Ten Break; // has an exit IF J> Length (s) dam // According to Result: = I 1; Break; // Complete end; end; freemem (p); end;