| |

VerySource

 Forgot password?
 Register
Search
View: 752|Reply: 8

Regarding TXT to find and delete duplicate data. Please help me

[Copy link]

4

Threads

19

Posts

17.00

Credits

Newbie

Rank: 1

Credits
17.00

 China

Post time: 2020-1-22 20:40:01
| Show all posts |Read mode
The text is as follows
aaaa
bbbb
ccc
ddd
aaaa
eee
fff
gggg

How to delete duplicates ~~ headache ~
Reply

Use magic Report

0

Threads

40

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-2-5 08:30:02
| Show all posts
procedure TForm1.Button1Click (Sender: TObject);
var
  s: TStringList;
  I: Integer;
begin
  s: = TStringList.Create;
....
  s.Sort;
  for i: = s.Count-1 downto 1 do
    if s [i] = s [i-1] then
      s.Delete (i);
    ...
end;
Reply

Use magic Report

4

Threads

19

Posts

17.00

Credits

Newbie

Rank: 1

Credits
17.00

 China

 Author| Post time: 2020-2-7 20:45:01
| Show all posts
I wrote this, but the problem is still not solved ~~ aaaa is still not deleted ~~

Lists: = TStringList.Create;
Lists.LoadFromFile (opendialog1.FileName);
progressbar1.Max: = lists.Count-1;
 for i: = lists.Count-1 downto 1 do
 begin
    if lists [i] = lists [i-1] then
    begin
      lists.Delete (i);
    lists.SaveToFile (opendialog1.FileName);
    end;
 end;
Reply

Use magic Report

0

Threads

40

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-2-7 22:15:01
| Show all posts
You are too careless to copy wrong

Lists: = TStringList.Create;
Lists.LoadFromFile (opendialog1.FileName);
Lists.Sort;
progressbar1.Max: = lists.Count-1;
 for i: = lists.Count-1 downto 1 do
 begin
    if lists [i] = lists [i-1] then
    begin
      lists.Delete (i);

    end;
 end;
lists.SaveToFile (opendialog1.FileName);
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-15 15:15:01
| Show all posts
There is a problem with your algorithm. Always compare the Nth string with the N-1th string. If it is not adjacent, it will be impossible to compare.
You should compare each one with any one of them.
Such as using the first and second to last comparison
Use the second and third to the last comparison
Use the third and fourth to last comparison
...
Only then can we compare them all
Reply

Use magic Report

0

Threads

3

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-17 11:15:01
| Show all posts
if s[i] = s[i-1] then
      s.Delete(i);

something wrong
Reply

Use magic Report

0

Threads

3

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-17 11:30:02
| Show all posts
The easiest way:
Open UltraEdit-File-Sort-Advanced Sort/Options-Select [Delete Duplicates]
Reply

Use magic Report

0

Threads

3

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-17 11:45:01
| Show all posts
sorry didn't see s.sort
But even so, it is not recommended to delete s in the count loop of i from s

In fact, it can also be written like this
procedure TForm1.Button1Click(Sender: TObject);
var
  s,b: TStringList;
  I: Integer;
begin
  s := TStringList.Create;
  b := TStringList.Create;

....
  for i := s.Count-1 downto 1 do
    if b.IndexOf(s[i])<0 then
      b.Add(s[i]);
    ...
b.SaveToFile
b.free;
s.free;
end;
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-17 12:30:01
| Show all posts
Simple problems are complicated

s := TStringList.Create;
s.Duplicates := dupIgnore;
s.Sorted := True;
try
s.LoadFromFile(XXXX);
finally
Freeandnil(s);
end;
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list