ESBPosNCh Function
Returns the Position of the n'th occurrence of given Character.

Unit
QESBPCSConvert

Declaration
Function ESBPosNCh(const Ch: Char; const S: string; const N: Integer; Start: Integer = 1): Integer;

Description
Can optionally have a starting point.

Parameters
Ch Character to be searched for
String to Search within
is the Occurrence that is being looked for. If N < 1 then 0 is returned.
Start Character Position at which to start. If Start < 1 then 1 is used. If Start > Length (S) then 0 is returned.

Returns
The Position of the Character, otherwise 0 is returned.

Category
Extra String Handling Routines

Implementation

function ESBPosNCh (const Ch: Char; const S: string; const N: Integer;
     Start: Integer = 1): Integer;
var
     I, Len, Count: Integer;
begin
     Result := 0;
     Len := Length (S);
     if Start < 1 then
          Start := 1;
     if (Len = 0) or (Start > Len) or (N < 1) then
          Exit;

     Count := 0;
     for I := Start to Len do
     begin
          if S [I] = Ch then
          begin
               Inc (Count);
               if Count = N then
               begin
                    Result := I;
                    Exit;
               end;
          end;
     end;
End;


HTML generated by Time2HELP
http://www.time2help.com