Delphi Tstrings save to UTF8 file format

How to save TStringLists with UTF8


Source

procedure TForm3.Button1Click(Sender: TObject);
var
  i: word;
  list: tstrings;
begin
  list := TStringList.Create;
  list.BeginUpdate;
  try
    for i := 0 to High(word) do
    begin
      list.Add(format('%d = %s', [i, chr(i)]));
    end;
    list.EndUpdate;
  finally
    list.SaveToFile('c:\temp\l.txt', TEncoding.UTF8);
    list.free;
  end;
end;

Comments