How can a text file be converted from ANSI to UTF-8 with Delphi 7?

后端 未结 6 1647
渐次进展
渐次进展 2021-01-11 18:48

I written a program with Delphi 7 which searches *.srt files on a hard drive. This program lists the path and name of these files in a memo. Now I need convert

6条回答
  •  抹茶落季
    2021-01-11 19:16

    The Utf8Encode function takes a WideString string as parameter and returns a Utf-8 string.

    Sample:

    procedure ConvertANSIFileToUTF8File(AInputFileName, AOutputFileName: TFileName);
    var
      Strings: TStrings;
    begin
      Strings := TStringList.Create;
      try
        Strings.LoadFromFile(AInputFileName);
        Strings.Text := UTF8Encode(Strings.Text);
        Strings.SaveToFile(AOutputFileName);
      finally
        Strings.Free;
      end;
    end;
    

提交回复
热议问题