Autor Beitrag
Asgar
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 160

XP Home Edition
D5
BeitragVerfasst: Mi 11.05.05 07:17 
Hallo,
Ich hab ein Programm wo ich einzelne Buchstaben aus einer Datei auslese, und jetzt überprüfen will ob sie gültig sind. Als Zeichen sind nur a-z, A-Z und 0-9 erlaubt, wie überprüfe ich das jetzt? habs erst mit
if Buchstabe in [a..z] versucht, aber das funktionierte nicht weil das anscheinend nur mit char geht. Der ausgelesene buchstabe ist allerdings ein String.
Hoffe ihr könnt mir sagen wie ich weiterkomme.
Gruß
Daniel
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mi 11.05.05 07:23 
Eine Möglichkeit:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure blabla;
var
  Buchstabe : String;
begin
  Buchstabe := 'A';
  if Buchstabe[1] = ... // so wird das als Char angesprochen
end;
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mi 11.05.05 07:26 
ausblenden Delphi-Quelltext
1:
Pos(Sub, Str);					

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Holgerwa
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 325

WIN XP Pro, Vista Business
Delphi 7 Pro, BDS 2006 Pro
BeitragVerfasst: Mi 11.05.05 07:30 
Hallo,

meinst Du so etwas?
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure xyz;
var s: string;
    i: integer;
begin
  s := 'Das ist der String';
  for i := 1 to Length (s) do
    if s[i] in ['a'..'z','A'..'Z','0'..'9'] then
      // Mach das, was Du tun willst...
end;

Holger
feivel3333
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 190

W7
Delphi XE prof
BeitragVerfasst: Mi 11.05.05 07:32 
Guten Morgen,
darf ich davon ausgehen, dass du diese Datei in einem String hast? Wenn nein, dann gehe ich in diesem Beispiel dennoch davon aus, und nenne diesen String csString.

Ich würde da folgendes machen:

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:
24:
niGrA := ord( 'A' );  // habe ich nur gemacht, da ich die ORDs nicht auswendig kenne
niGrZ := ord( 'Z' );  // und es die Sache besser veranschaulicht
niKlA := ord( 'a' );
niKlZ := ord( 'z' );
ni0   := ord( '0' );
ni9   := ord( '9' );
lbOK  := true;

niI := length( csString )-1;
for niI := 0 to niI do begin
   csBuchstabe := copy( csString, niI, 1 );
   if ( ( ord( csBuchstabe ) >= niGrA ) and ( ord( csBuchstabe <= niGrZ ) ) or
      ( ( ord( csBuchstabe ) >= niKlA ) and ( ord( csBuchstabe <= niKlZ ) ) or
      ( ( ord( csBuchstabe ) >= ni0 ) and ( ord( csBuchstabe <= ni9 ) ) then 
      // Ich habe die Logik etwas verdreht, an dieser Stelle passiert bewusst nix!
   else
      lbOK := false;
   application.processmessages;
end;

// Hier kannst du nun lbOK auswerten.
if lbOK = false then begin
   // Meckern oder sonst was
end;

Sollte es nicht funktionieren, dann bitte reklamieren. Ich habe es mir in fünf minuten vor der Arbeit zusammengekloppt. Testen konnte ich es nicht mehr.

Gruß, AS

Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt.
Asgar Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 160

XP Home Edition
D5
BeitragVerfasst: Mi 11.05.05 07:36 
ok, jetzt gehts bei mir, vielen Dank für die schnelle Antwort.
Gruß
Daniel
crakos
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 195


D2k5 Pers
BeitragVerfasst: Mi 11.05.05 21:08 
naja der code geht auch kürtzer, Ich filter großbuchstaben bei einer verschlüsselung hiermit aus
ausblenden Delphi-Quelltext
1:
2:
3:
  for i:=1 to length(orgtext) do
    if (ord(orgtext[i])<=90) and (ord(orgtext[i])>=65) then
      vertext:=vertext+orgtext[i];

für dich würds dann
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
for i:=1 to length(orgtext) do
  if (ord(orgtext[i])<=90) and (ord(orgtext[i])>=65) //90=Z 65=A
  or (ord(orgtext[i])<=122) and (ord(orgtext[i])>=97) //122=z 97=a
  or (ord(orgtext[i])<=57) and (ord(orgtext[i])>=48)  then //57=9 48=0
      vertext:=vertext+orgtext[i];
sein

_________________
Das Ende der Menschheit ist der Anfang der Unendlichkeit.


Zuletzt bearbeitet von crakos am Do 12.05.05 13:55, insgesamt 1-mal bearbeitet
Asgar Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 160

XP Home Edition
D5
BeitragVerfasst: Do 12.05.05 08:05 
hab den Code von Holgerwa benutzt der is irgendwie am einfachsten und er funktioniert.
crakos
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 195


D2k5 Pers
BeitragVerfasst: Do 12.05.05 13:52 
der code ist einfacher????????????
also welcher code einfacher ist, steht da wohl ausßer frage Oo

_________________
Das Ende der Menschheit ist der Anfang der Unendlichkeit.
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: Do 12.05.05 13:58 
nur das dein code faslch ist weil

Zitat:

or (ord(orgtext[i])<=57) and (ord(orgtext[i])>=0) then


sind bestimmt nicht nur zahlen

EDIT: hast ja noch schnell geändert 8)

_________________
wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit
crakos
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 195


D2k5 Pers
BeitragVerfasst: Do 12.05.05 14:07 
ja das kommt davon wenn man im stress ist, denkt an die asci zahl von 0 will 48 schreiben und schreibt 0 ......

_________________
Das Ende der Menschheit ist der Anfang der Unendlichkeit.