Online
Registriert seit: 11. Okt 2003
Ort: Elbflorenz
44.063 Beiträge
Delphi 12 Athens
|
Re: Nach Alphabet sortieren (ValueListEditor)
29. Nov 2003, 22:23
Ein Hallöle von http://www.FrankNStein.de/Smiley-Wolke.gif,
Die Einfache Variante:
Delphi-Quellcode:
Var I, I2: Integer;
S: String;
For I := 0 to ValueListEditor1.Strings.Count - 2 do
For I2 := I + 1 to ValueListEditor1.Strings.Count - 1 do
If ValueListEditor1.Strings[I] > ValueListEditor1.Strings[I2] Then Begin
S := ValueListEditor1.Strings[I];
ValueListEditor1.Strings[I] := ValueListEditor1.Strings[I2];
ValueListEditor1.Strings[I2] := S;
End;
ValueListEditor1.Strings[...] enthält eine Kombination aus Schlüssel und Wert ("Schlüssel=Wert") und wenn genauer sortiert werden soll, muß der String geteilt werden.
Nach Schlüssel:
Delphi-Quellcode:
Var I, I2: Integer;
S, S2: String;
For I := 0 to ValueListEditor1.Strings.Count - 2 do
For I2 := I + 1 to ValueListEditor1.Strings.Count - 1 do Begin
S := Copy(ValueListEditor1.Strings[I], 1, Pos('=',
ValueListEditor1.Strings[I] - 1);
S2 := Copy(ValueListEditor1.Strings[I2], 1, Pos('=',
ValueListEditor1.Strings[I2] - 1);
If S > S2 Then Begin
S := ValueListEditor1.Strings[I];
ValueListEditor1.Strings[I] := ValueListEditor1.Strings[I2];
ValueListEditor1.Strings[I2] := S;
End;
End;
Nach Wert:
Delphi-Quellcode:
Var I, I2: Integer;
S, S2: String;
For I := 0 to ValueListEditor1.Strings.Count - 2 do
For I2 := I + 1 to ValueListEditor1.Strings.Count - 1 do Begin
S := Copy(ValueListEditor1.Strings[I], Pos('=',
ValueListEditor1.Strings[I] + 1, Length(ValueListEditor1.Strings[I]));
S2 := Copy(ValueListEditor1.Strings[I2], Pos('=',
ValueListEditor1.Strings[I2] + 1, Length(ValueListEditor1.Strings[I2]));
If S > S2 Then Begin
S := ValueListEditor1.Strings[I];
ValueListEditor1.Strings[I] := ValueListEditor1.Strings[I2];
ValueListEditor1.Strings[I2] := S;
End;
End;
Oder mal eine Hochgenaue Variante for Schlüssel
Delphi-Quellcode:
Var I, I2: Integer;
S, S2, S3, S4: String;
For I := 0 to ValueListEditor1.Strings.Count - 2 do
For I2 := I + 1 to ValueListEditor1.Strings.Count - 1 do Begin
S := Copy(ValueListEditor1.Strings[I], 1, Pos('=',
ValueListEditor1.Strings[I] - 1);
S2 := Copy(ValueListEditor1.Strings[I], Pos('=',
ValueListEditor1.Strings[I] + 1, Length(ValueListEditor1.Strings[I]));
S3 := Copy(ValueListEditor1.Strings[I2], 1, Pos('=',
ValueListEditor1.Strings[I2] - 1);
S4 := Copy(ValueListEditor1.Strings[I2], Pos('=',
ValueListEditor1.Strings[I2] + 1, Length(ValueListEditor1.Strings[I2]));
While Length(S) < Length(S3) do S := S + ' ';
While Length(S3) < Length(S) do S3 := S3 + ' ';
While Length(S2) < Length(S4) do S2 := S2 + ' ';
While Length(S4) < Length(S2) do S4 := S4 + ' ';
If (S > S3) or ((S = S3) and (S2 > S4)) Then Begin
S := ValueListEditor1.Strings[I];
ValueListEditor1.Strings[I] := ValueListEditor1.Strings[I2];
ValueListEditor1.Strings[I2] := S;
End;
End;
Und noch mal für Wert:
Delphi-Quellcode:
Var I, I2, I3: Integer;
S, S2, S3, S4: String;
For I := 0 to ValueListEditor1.Strings.Count - 2 do
For I2 := I + 1 to ValueListEditor1.Strings.Count - 1 do Begin
S := Copy(ValueListEditor1.Strings[I], 1, Pos('=',
ValueListEditor1.Strings[I] - 1);
S2 := Copy(ValueListEditor1.Strings[I], Pos('=',
ValueListEditor1.Strings[I] + 1, Length(ValueListEditor1.Strings[I]));
S3 := Copy(ValueListEditor1.Strings[I2], 1, Pos('=',
ValueListEditor1.Strings[I2] - 1);
S4 := Copy(ValueListEditor1.Strings[I2], Pos('=',
ValueListEditor1.Strings[I2] + 1, Length(ValueListEditor1.Strings[I2]));
While Length(S) < Length(S3) do S := S + ' ';
While Length(S3) < Length(S) do S3 := S3 + ' ';
While Length(S2) < Length(S4) do S2 := S2 + ' ';
While Length(S4) < Length(S2) do S4 := S4 + ' ';
If (S2 > S4) or ((S2 = S4) and (S > S3)) Then Begin
S := ValueListEditor1.Strings[I];
ValueListEditor1.Strings[I] := ValueListEditor1.Strings[I2];
ValueListEditor1.Strings[I2] := S;
End;
End;
http://www.FrankNStein.de/Smiley-Kuss.gif * * http://www.FrankNStein.de/Smiley-Spinne.gif * * * http://www.FrankNStein.de/Smiley-Winken.gif
Neuste Erkenntnis:
Seit Pos einen dritten Parameter hat,
wird PoSex im Delphi viel seltener praktiziert.
|