Mam w listbox takie przykładowe dane:
1 1 1 2 3 4 2 1 1 1 1 1 2 2 2 2 1 1 2
1 1 1 2 3 4 2 1 1 1 1 1 2 2 2 2 6 6 6
a chciałbym uzyskać postać bardziej uproszczona a mianowicie aby uzyskac:
1 2 3 4 2 1 2 1 2
1 2 3 4 2 1 2 6
Jaka funkcję zastosować aby uzyskać wskazany efekt?
Zrobiłem to tak choć nieporagnie wygląda ten kod
procedure TForm1.Button1Click(Sender: TObject);
var
i, ii, iii, a, b : integer;
sl, sl1, sl2 : TStringList;
s1, s2, s3 : string;
begin
sl := TStringList.Create;
sl1 := TStringList.Create;
sl2 := TStringList.Create;
for ii := 0 to ListBox1.Items.Count -1 do
begin
sl1.Clear;
sl2.Clear;
ExtractStrings([' ',' '], [], PChar(ListBox1.Items[ii]),sl2);
for iii := 0 to sl2.Count -1 do
begin
sl2.Insert(iii,sl2[sl2.Count-1]);
sl2.Delete(sl2.Count-1);
end;
sl2.Insert(0,'');
for i := sl2.Count -1 downto 1 do
begin
s1 := sl2[i];
s2 := sl2[i-1];
if s1 = s2 then inc(a);
if s1 = s2 then sl.Text := sl2[i];
if s1 <> s2 then sl.Text := sl2[i];
if s1 <> s2 then a := 0;
if s1 <> s2 then sl1.Add(sl[sl.Count-1]);
if i = 1 then break;
application.ProcessMessages;
end;
s3 := sl1.DelimitedText;
s3 := StringReplace(s3, ',', ' ', [rfReplaceAll]);
showmessage(s3);
end;
sl.free;
sl1.free;
sl2.free;
end;