Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Case of komrpimieren (https://www.delphipraxis.net/103971-case-komrpimieren.html)

Chrissi91 25. Nov 2007 14:46


Case of komrpimieren
 
Hi,

wie ging das gleich noch, wenn man nicht alles tippen will?

Delphi-Quellcode:
case Random(62) of
  0: S := 'A';
  1: S := 'B';
  ...
  26: S := 'a';
  27: S := 'b';
  ...
  52: S := '0';
  53: S := '1';
  ...
end;
Ich habe keine Lust von 0 - 61 alles hinzuschreiben. Hatte schonmal eine kürzere Möglichkeit gelesen, aber wie ging die noch gleich? :lol:

DGL-luke 25. Nov 2007 14:46

Re: Case of komrpimieren
 
Ehm... suchst du Delphi-Referenz durchsuchenOrd und Delphi-Referenz durchsuchenChr?

freak4fun 25. Nov 2007 14:50

Re: Case of komrpimieren
 
Du kannst da was zusammenfassen:
Delphi-Quellcode:
Zahl := Random(62);
case Zahl of
  0..25: S := Char(Zahl + ASCII-Wert);
  26..51: S := Char(Zahl + ASCII-Wert);
  52..61: S := Char(Zahl + ASCII-Wert);
end;
Schau dir dazu mal die Werte in der ASCII-Tabelle an. ;)

Namenloser 25. Nov 2007 15:27

Re: Case of komrpimieren
 
Du könntest auch mit einem Array arbeiten.
Delphi-Quellcode:
const
  chars: array[0..61] of char = ('A','B','C','D',...,'a','b',...,'0','1,'2'...);
...
  char = chars[random(62)];


Alle Zeitangaben in WEZ +1. Es ist jetzt 15:11 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz