如何使用 Delphi 7 将文本文件从 ANSI 转换为 UTF-8? [英] How can a text file be converted from ANSI to UTF-8 with Delphi 7?

查看:84
本文介绍了如何使用 Delphi 7 将文本文件从 ANSI 转换为 UTF-8?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 Delphi 7 编写了一个程序,用于搜索硬盘驱动器上的 *.srt 文件.该程序在备忘录中列出了这些文件的路径和名称.现在我需要将这些文件从 ANSI 转换为 UTF-8,但我没有成功.

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 these files from ANSI to UTF-8, but I haven't succeeded.

推荐答案

Utf8Encode 函数接受一个 WideString 字符串作为参数并返回一个 Utf-8 字符串.

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

示例:

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;

这篇关于如何使用 Delphi 7 将文本文件从 ANSI 转换为 UTF-8?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆