Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
德尔福 2010
使用readLn过程从文件读取时,默认情况下,我会从代码页 1251(Windows 的代码页)转换而来的 unicode 字符串。
我怎样才能改变它并从其他代码页中的文件中读取,在 1252 或 UTF16 中?
不要将 ReadLn/WriteLn 用于新代码。正如 Michael Madsen 所建议的,在 SysUtils 中使用 TStreamReader。
您可以使用 TStreamReader - 您可以在构造它时指定要读取的编码。
例如,TStreamReader.Create(FileName, TEncoding.UTF8);将创建一个 TStreamReader,它可用于从 FileName 中指定的文件中读取文本,使用 UTF-8 作为编码。
TStreamReader.Create(FileName, TEncoding.UTF8);