...extract eMail adresses from a csv file?
Author: Dev4u.ch
//you need a Tlistbox, aTButton, aTLabel
procedure readcsv(liste: string);
var
i, b, at, lang, anfang, ende: Integer;
email, csv: TStringList;
found1, found2, atf: Boolean;
begin
csv := TStringList.Create;
csv.LoadFromFile(liste); // die angegeben csv auslesen
email := TStringList.Create;
email.Sorted := True;
found1 := False;
found2 := False;
atf := False;
for i := csv.Count - 1 downto 0 do
begin
for b := Length(csv.Strings[i]) downto 1 do
begin
if csv.Strings[i][b] = '@' then
begin
at := b; //das @ suchen
atf := True;
end;
end; //ende Buchstabe
if atf = True then //Wenn @ gefunden
begin
for b := at downto 1 do
begin
if found1 = False then
begin
if b = 1 then //Wenn Email am Anfang beginnt
begin
anfang := b;
found1 := True; //anfang der E-Mail gefunden
end;
if csv.Strings[i][b] = ';' then //Den ; vor dem @ suchen
begin
anfang := b + 1;
found1 := True; //anfang der E-Mail gefunden
end;
end;
end; //ende suche begin
found1 := False;
for b := at to Length(csv.Strings[i]) do
begin
if csv.Strings[i][b] = ';' then
begin
if found2 = False then
begin
ende := b;
found2 := True; //Ende der E-Mail gefunden
end;
end;
end; //ende suche begin
found2 := False;
lang := ende - anfang; //Länge der Email-Adresse herausfinden
email.Add(Copy(csv.Strings[i], anfang, lang)); //Die E-Mail zur Stringlist hinzufügen
atf := False;
end; //ende zeilen
end; //ende ohne at
Form1.ListBox1.Clear;
Form1.listbox1.Items.addstrings(email);
Form1.Label1.Caption := IntToStr(Form1.listbox1.Items.Count) + ' E-Mails gefunden!!';
csv.Free;
email.Free;
end; //ende readcsv
procedure TForm1.Button1Click(Sender: TObject);
begin
readcsv('c:\test.csv'); //die Liste angeben
end;
printed from
www.swissdelphicenter.ch
developers knowledge base