Autor Beitrag
rabby
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 61

gentoo

BeitragVerfasst: Sa 01.05.04 17:25 
hallo welt !

wie mach ich am geschicktesten eine fkt, die prüft, ob sich in nem string (ausschließlich) diese struktur wieder finden '%nn' => also dollar und dann 2 ziffern.

danke
aM0xACiLLiN
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 64



BeitragVerfasst: Sa 01.05.04 18:11 
Hi,

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
function string_pruefen(str:string):boolean;
const numbers:string = '0123456789';
begin
result:=(copy(str,1,1) = '$') and (Pos(copy(str,2,1),numbers) > 0) and (Pos(copy(str,3,1),numbers) > 0);
end;


cu
rabby Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 61

gentoo

BeitragVerfasst: Sa 01.05.04 18:39 
naja, so trivial is es nun auch wieder ned...
diese struktur kann sich auch öfter wiederfinden....


ausblenden volle Höhe Quelltext
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:
  ok:=1;
  for i:=0 to length(str) do
  begin
    done:=0;

    if(l=1) AND (done=0)then
    begin
      if(nummer_pruefen(str[i])<>true)then
      begin
        ok:=0;                       showmessage(str[i]);
      end;
      l:=2;
      done:=1;
    end;

    if(l=2) AND (done=0)then
    begin
      if(nummer_pruefen(str[i])<>true)then
      begin
        ok:=0;                  showmessage(str[i]);
      end;
      l:=3;
      done:=1;
    end;

    if(l=3) AND (done=0)then
    begin
      if(str[i]<>'%')then
      begin
        ok:=0;                           showmessage(str[i]);
      end;
      l:=1;
      done:=1;
    end;

    str2:=str2+str[i];
  end;


hierbei is noch der fehler, dass str[i] irgendwie nicht richtig ermittelt wird...
is immer leer !
sollte den geannten char des strings holen...

wie gehst?
aM0xACiLLiN
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 64



BeitragVerfasst: Sa 01.05.04 19:18 
Hi,

du willst doch nur wissen ob ein string "$xx" ist, für x jeweils eine zahl, oder?
Was passt dir dann an meiner Methode nicht?

cu
rabby Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 61

gentoo

BeitragVerfasst: Sa 01.05.04 19:38 
es kann ja auch so aussehn $xx$xx$xx usw...

sag mir doch bitte wie ich den n-ten buchstabe vom string str rausfinden kann...
str[n] geht ja wie schon gesagt nicht :-(
aM0xACiLLiN
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 64



BeitragVerfasst: Sa 01.05.04 19:44 
Hi,

achso. Sag das doch dazu..

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
function pruefe_string(str: string):boolean;
var t:string;
begin
t:=str;
result:=(length(t) > 0);
while (length(t) > 0) do begin
 if (copy(t,1,1) = '$') and (Pos(copy(t,2,1),numbers) > 0) and (Pos(copy(t,3,1),numbers) > 0) then
  Delete(t,1,3) else begin
  result:=false;
  Exit;
 end;
end;
end;


Ein zeichen von einem String herausbekommen: copy(string,anfang,länge);
Aber probier's erstmal mit meiner methode, die um einiges schlanker ist als deine..

cu
rabby Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 61

gentoo

BeitragVerfasst: Sa 01.05.04 22:30 
so... nun hab ich irgendwie noch ein wenig rumgebastelt...
nun gehts einwandfrei.
danke!