1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| unit Ex01a;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
Tmaliste = array of ShortString;
TForm1 = class(TForm)
Button1: TButton;
Label2: TLabel;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
temp:ShortString;
tableau:Tmaliste;
implementation
{$R *.DFM}
//... Sépare les mots d'une chaine qui sont liés par le séparateur indiqué .....................
function separe(chaine : ShortString; sep : char) : Tmaliste;
var i1,taille,position:integer;
mot:ShortString;
t1 :Tmaliste;
begin
taille := 1 ;
for i1 := 1 to Length(chaine)-1 do
if chaine[i1] = sep then
taille := taille + 1 ;
SetLength (t1, taille) ;
position := -1 ;
while pos(sep,chaine) > 0 do // tant que l'on trouve un séparateur
begin
// extraction du mot
mot := copy (chaine,1,pos (sep,chaine)-1) ;
// Suppression de la partie traitée
delete (chaine,1,pos (sep,chaine)) ;
position := position + 1 ;
t1[position] := mot ;
end ;
if chaine <> '' then
begin
position := position + 1 ;
t1[position] := chaine ;
end ;
result := t1 ;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i1 : integer ;
begin
Edit1.text:='pied*velo*auto*train*';
tableau:=separe(Edit1.text,'*');
temp := '' ;
for i1 := 0 to SizeOf (tableau)-1 do
temp := temp + ' ' + tableau[i1] ;
Label2.caption := temp ;
end;
end. |
Partager