There are lines in the text file:

Документ№1:22.06.2018 Документ№2:22.06.2018 Документ№3:22.06.2018 Документ№1:23.05.2018 Документ№1:25.05.2018 

Task: Delete all duplicate rows (leaving one unique).

Special condition: The same , the line is considered, in which, before the symbol ":" - the words are repeated (in our case - Document # 1 ).

Result at the exit:

 Документ№1:22.06.2018 Документ№2:22.06.2018 Документ№3:22.06.2018 

Standard, deleting duplicate rows is not a problem for me. But in this case, with the task, I can not cope.

  • 2
    And what causes difficulties? - Anton Shchyrov
  • one
    In a stringlist, what thread valueseparator should be set to : and download the content, for sure, probably unique entries will remain only. the truth is most likely the aftermath. - teran
  • one
    Pos and Copy functions or the String.Split method will help you - Anton Shchyrov
  • one
    @teran Will not stay. All records will be loaded. But Values[] will return the first entry for the specified name - Anton Shchyrov
  • one
    Well, show me how you tried - Anton Shchyrov

1 answer 1

 var Strings: TDictionary<string, string>; Str: string; Key: string; begin Strings := TDictionary<string, string>.Create; try while ... do begin Str := ReadString; Key := Copy(Str, 1, Pos(':', Str) - 1); if not Strings.ContainsKey(Key) then Strings.Add(Key, Str); end; for Str in Strings.Values do WriteString(Str); finally end; end; 
  • Excellent solution. I was in a pleasant shock, I didn’t even think that everything was so simple. Low bow to you - Anton Shchyrov! - Tatiana