How can you sort the rows in the specified order. That is, I specify the order in which the lines should go - Brend then Nomer_tovara then Year then Garantiya

For example (input file):

Nomer_tovara: 557436 Brend: VMS Garantiya: 2343454 Year : 2019 Nomer_tovara: 557436 Brend: ORP Garantiya: 78788777 Year : 2019 

Output file:

 Brend: VMS Nomer_tovara: 557436 Year : 2019 Garantiya: 2343454 Brend: ORP Nomer_tovara: 557436 Year : 2019 Garantiya: 78788777 

    1 answer 1

      function LineNumber(value: string): Integer; begin if value = 'Brend' then Result := 0 else if value = 'Nomer_tovara' then Result := 1 else if value = 'Year ' then Result := 2 else if value = 'Garantiya' then Result := 3 else Result := -1; end; var sl: TStringList; i, block_line, line_number: Integer; begin sl := TStringList.Create; sl.NameValueSeparator := ':'; sl.LoadFromFile('...'); i := 0; block_line := 0; while i < sl.Count do begin if sl.Strings[i] = '' then begin block_line := i + 1; Inc(i); Continue; end; line_number := LineNumber(sl.Names[i]); if (line_number > -1) and (line_number <> i - block_line) then sl.Exchange(i, block_line + line_number) else Inc(i); end; sl.SaveToFile('....'); sl.Free; end;