Autor Beitrag
Deerfield
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 35


Delphi XE Pro
BeitragVerfasst: Do 11.05.06 14:59 
Hallo,

wenn ich einen String der Form '012354' habe, wie kann ich den aufsteigend in die Form '012345' sortieren?

Grüße,
Deerfield
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 11.05.06 15:04 
Moin!

Du kannst einen String auch als array[] of Char betrachten und dann sortieren:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
var
  MyString: String;
  tmp: Char;

MyString := '41320769';

if (MyString[1] > MyString[2]) then begin
  tmp := MyString[1];
  MyString[1] := MyString[2];
  MyString[2] := temp;
end;

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Deerfield Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 35


Delphi XE Pro
BeitragVerfasst: Do 11.05.06 15:48 
Nunja, ich würde gern den String als Parameter an eine Funktion übergeben, da seine Länge variabel ist. Und das ganze muss irgendwie in eine Schleife, damit alle Elemente sortiert werden. Zurückgegeben werden soll der sortierte String. Ich experimentiere gerade mit Arrays rum, aber irgendwie klappt das nicht so richtig...