Przypuśćmy, ze w listbox mam pewne znaki:
2011-11-01 a b c d => [1][2][2][1]
2011-11-02 a c d f => [1][4][2][4]
2011-11-03 f d d g => [1][2][2][1]
2011-11-04 a b c d => [3][2][3][1]
2011-11-05 a b c d => [3][3][3][1]
a powinno być dla mnie
2011-11-01 a b c d => [1][2]
2011-11-02 a c d f => [1][2][4]
2011-11-03 f d d g => [1][2]
2011-11-04 a b c d => [3][2][1]
2011-11-05 a b c d => [3][1]
chodzi mi o usunięcie duplikatów po znaku =>
Dla [1] Robię tak:
implementation
{$R *.dfm}
function CountPos(const subtext: string; Text: string): Integer;
begin
if (Length(subtext) = 0) or (Length(Text) = 0) or (Pos(subtext, Text) = 0) then
Result := 0
else
result := (Length(Text) - Length(StringReplace(Text, subtext, '', [rfReplaceAll]))) div
Length(subtext);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i : integer;
s : string;
sl : TStringList;
begin
sl := TStringList.Create;
sl.Clear;
sl.Text := ListBox1.Items.Text;
for i := 0 to ListBox1.Items.Count -1 do
begin
s := inttostr(countpos('[1]', copy(sl[i],22,1000)));
if s > '1' then
sl[i] := copy(sl[i],0,22) + StringReplace(copy(sl[i],23,1000), '[1]', '', []);
ListBox1.items.text := sl.text;
end;
sl.free;
end;
gdyby się okazało że :
2011-11-01 a b c d => [1][2][2][1][1]
to musiałbym wcisnąć drugi raz button.