Inno Setup替换不带BOM的UTF-8文件中的字符串 [英] Inno Setup replace a string in a UTF-8 file without BOM

查看:168
本文介绍了Inno Setup替换不带BOM的UTF-8文件中的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要更改配置文件中的某些值.该文件是没有BOM的UTF-8.我需要以相同的方式保存它.我该如何使用Inno Setup Unicode版?注意:不起作用,并且此未显示如何正确读取文件.

I need to change some values in a configuration file. The file is UTF-8 without BOM. I need to save it the same way. How do I do it with Inno Setup Unicode edition? Note: This doesn't work, and this doesn't show how to read the file correctly.

推荐答案

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;

LoadStringFromFileInCPSaveStringToFileInCP来自: Inno设置-将字符串数组转换为Unicode并转换回ANSI

LoadStringFromFileInCP and SaveStringToFileInCP come from:
Inno Setup - Convert array of string to Unicode and back to ANSI

代码需要Unicode版本的Inno Setup(Inno Setup 6唯一的版本).
对于Unicode字符串文字,您的.iss文件必须采用带有BOM的UTF-8编码.

The code needs Unicode version of Inno Setup (the only version as of Inno Setup 6).
For Unicode string literals, your .iss file must be in UTF-8 encoding with BOM.

这篇关于Inno Setup替换不带BOM的UTF-8文件中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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