PosEx (rtl)

De Wiki1000
Révision datée du 11 août 2009 à 13:50 par Syfre (discussion | contributions)
(diff) ← Version précédente | Voir la version actuelle (diff) | Version suivante → (diff)

<source lang='delphi'>Function PosEx(const SubStr:string; const S:string; Offset:Integer):Integer;</source>

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 <source lang='delphi'> 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; </source>

Voir aussi:

{{#if:Développement DSM|

{{#if:Développement DSM|— Développement DSM |}} — Développement DSM

|

{{#if:|— [[{{{1}}}]] |}} — Développement DSM

}}