Autor Beitrag
sagar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27



BeitragVerfasst: So 05.08.07 12:33 
Hallo!
Ich habe ein Memo, worin der Text einer Rechnung steht.
Nun möchte ich die PLZ auslesen. Es ist die einzige fünfstellige Zahl.

Gibt es eine Methode, welche 5 beliebige Ziffern sucht ?
arj
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 378

Win XP/Vista, Debian, (K)Ubuntu
Delphi 5 Prof, Delphi 7 Prof, C# (#Develop, VS 2005), Java (Eclipse), C++, QT, PHP, Python
BeitragVerfasst: So 05.08.07 12:42 
Such mal nach Regular Expressions im Forum. Damit ist sowas möglich.
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: So 05.08.07 15:11 
das geht auch ohne ;)

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
var
  i, j, c: integer;
  tmpstr: string;
begin
  for i := 2 to length(memo1.text) do
  begin
    tmpstr := copy(memo1.text, i - 1, 7);
    // muss 5 stellen lang sein, nicht länger
    if (tmpstr[1] in ['0'..'9']) then
      continue;
    if (tmpstr[7] in ['0'..'9']) then
      continue;

    delete(tmpstr, 1, 1);
    delete(tmpstr, 6, 1);
    c := 0;
    for j := 1 to 5 do
      if (tmpstr[j] in ['0'..'9']) then inc(c);
    if (c = 5) then
      break;
  end;
  showmessage('Die PLZ lautet: ' + tmpstr);
end;

so sollte das gehen ;)

mfg
arj
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 378

Win XP/Vista, Debian, (K)Ubuntu
Delphi 5 Prof, Delphi 7 Prof, C# (#Develop, VS 2005), Java (Eclipse), C++, QT, PHP, Python
BeitragVerfasst: So 05.08.07 15:39 
ok ;) oder so ;) dann halt ohne regex *g*