【发布时间】:2019-01-23 17:57:08
【问题描述】:
我需要更改配置文件中的一些值。该文件是没有 BOM 的 UTF-8。我需要以同样的方式保存它。如何使用 Inno Setup Unicode 版本进行操作?注意:This 不起作用,this 没有显示如何正确读取文件。
【问题讨论】:
标签: utf-8 inno-setup byte-order-mark
我需要更改配置文件中的一些值。该文件是没有 BOM 的 UTF-8。我需要以同样的方式保存它。如何使用 Inno Setup Unicode 版本进行操作?注意:This 不起作用,this 没有显示如何正确读取文件。
【问题讨论】:
标签: utf-8 inno-setup byte-order-mark
const
CP_UTF8 = 65001;
{ ... }
var
FileName: string;
S: string;
begin
FileName := 'test.txt';
if not LoadStringFromFileInCP(FileName, S, CP_UTF8) then
begin
Log('Error loading the file');
end
else
if StringChangeEx(S, 'žluťoučký kůň', 'ďábelské ódy', True) <= 0 then
begin
Log('No value was replaced');
end
else
if not SaveStringToFileInCP(FileName, S, CP_UTF8) then
begin
Log('Error writing the file');
end
else
begin
Log('Replacement successful');
end;
end;
LoadStringFromFileInCP和SaveStringToFileInCP来自:
Inno Setup - Convert array of string to Unicode and back to ANSI
代码需要 Inno Setup 的 Unicode 版本(Inno Setup 6 的唯一版本)。
对于 Unicode 字符串文字,您的 .iss 文件必须采用带有 BOM 的 UTF-8 编码。
【讨论】: