[fpc-devel] Addition for StrUtils unit: PosSetEx

Micha Nelissen micha at neli.hopto.org
Thu Dec 29 13:17:57 CET 2005


Hi,

I needed a function to find the first position where one of a set of
characters matches in a string. Alike C function 'strpbrk' if you know it.

Example:

PosSetEx('abcde', 'hello', 1);

Returns 2, because the 'e' is in second position. If no occurance, 0 is
returned (like Pos). The last parameter is the position from where to start
searching (assumes >= 1). PosSet(A,B) can be made by calling PosSetEx
(A,B,1);

Micha


---

function PosSetEx(const ASubStrSet, AString: string;
  const Offset: integer): integer;
begin
  for Result := Offset to Length(AString) do
    if Pos(AString[Result], ASubStrSet) > 0 then
      exit;
  Result := 0;
end;




More information about the fpc-devel mailing list