« PosEx (rtl) » : différence entre les versions

De Wiki1000
Aucun résumé des modifications
 
Aucun résumé des modifications
Ligne 1 : Ligne 1 :
<source lang='delphi'>Function PosEx(const SubStr:string; const S:string; Offset:Integer):Integer;</source>
<source lang='delphi'>Function PosEx(const SubStr:string; const S:string; Offset:Integer):Integer;</source>


description
Cette fonction retourne la position d'une sous chaîne dans une chaîne en commençant à une certaine position.


{|class="wikitable"
{|class="wikitable"
|-
|-
|Result
|Result
|
|Position de la sous chaîne, 0 si pas trouvé.
|-
|-
|SubStr
|SubStr
|
|Sous chaîne recherchée.
|-
|-
|S
|S
|
|Chaîne
|-
|-
|Offset
|Offset
|
|Position de début de recherche.
|-
|Result
|
|}
|}


Exemple
Exemple


'''Implémentation de la fonction StringPart'''
<source lang='delphi'>
<source lang='delphi'>
function StringPart(const AString,ASep:string; Index:Integer):string;
var xs,xe:Integer;
begin
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;
end;
</source>
</source>


Voir aussi:
Voir aussi:
*[[StringPart (rtl)|StringPart]]


{{Footer|Développement DSM}}
{{Footer|Développement DSM}}
[[category:RTL Chaîne]]
[[category:RTL Chaîne]]

Version du 11 août 2009 à 13:48

<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

}}