PosEx (rtl)
Function PosEx(const SubStr:string; const S:string; Offset:Integer):Integer;
Cette fonction retourne la position d'une sous chaîne dans une chaîne en commençant à une certaine position.
| Result | Position de la sous chaîne, 0 si pas trouvé. |
| SubStr | Sous chaîne recherchée. |
| S | Chaîne |
| Offset | Position de début de recherche. |
Exemple
Implémentation de la fonction StringPart
function StringPart(const AString,ASep:string; Index:Integer):string;
var xs,xe:Integer;
begin
xs := 1;
while xs<=length(AString) do
begin
xe := PosEx(ASep,AString,xs);
if xe<>0 then
begin
if Index=0 then
begin
Result := Copy(AString,xs,xe-xs);
Exit;
end;
xs := xe+1;
end
else
begin
if Index=0 then
begin
Result := Copy(AString,xs,length(AString)-xs+1);
Exit;
end;
xs := length(AString)+1;
end;
dec(Index);
end;
Result := '';
end;
Voir aussi: