PosEx (rtl)
De Wiki1000
(Différences entre les versions)
| 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> | ||
| − | + | 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. |
| − | + | ||
| − | + | ||
| − | + | ||
|} | |} | ||
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 à 14:48
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:
| Whos here now: Members 0 Guests 0 Bots & Crawlers 2 |