Autor Beitrag
motion
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 295

XP, Linux
D7 Prof
BeitragVerfasst: So 13.03.05 20:50 
Ich muss in einer Applikation einen Set of Chars in einen String umwandeln.
Kennt da jemand eine elegante Art, das zu tun?

Beispiel:
Validchars=['0'..'9','a'..'z','A'..'Z',' '];

soll umgewandelt werden in einen String:
sValidChars='0123456789abcdef...XYZ';
EUOCheffe
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 124



BeitragVerfasst: Mo 14.03.05 01:11 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
type 
  TCharSet = set of Char;

function CharSetToStr(CharSet : TCharSet) : String;
var
  i : Integer;
begin
  Result:='';
  for i:=0 to 255 do
    if Char(i) in CharSet then Result:=Result+Char(i);
end;

procedure TForm1.Button1Click(Sender: TObject);
const
  ValidChars = ['0'..'9','a'..'z','A'..'Z',' '];
begin
  ShowMessage(CharSetToStr(ValidChars));
end;
motion Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 295

XP, Linux
D7 Prof
BeitragVerfasst: Mo 14.03.05 21:34 
Vielen Dank für die Routine.
Ich hatte gehofft, es mit einer Art Type-Casting zu lösen, aber da jedes Element des Set's in einem Bit gespeichert wird (32 Bytes insgesamt für das Set of Char) ist eine solche Schleife wohl der beste Ansatz. Andere Bit-Friemeleien sind viel zu aufwendig.

Funktioniert wunderbar!