如何使用Inno Setup保存带有BOM表文件的UTF-16 [英] How to save a UTF-16 with BOM file with Inno Setup
本文介绍了如何使用Inno Setup保存带有BOM表文件的UTF-16的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将字符串保存到具有BOM表的UTF-16(UCS-2)编码的文本文件中?
How to save a string to a text file with UTF-16 (UCS-2) encoding with BOM?
SaveStringsToUTF8File
另存为UTF-8.
使用流将其另存为ANSI.
Using streams saves it as ANSI.
var
i:integer;
begin
for i := 1 to length(aString) do begin
Stream.write(aString[i],1);
Stream.write(#0,1);
end;
stream.free;
end;
推荐答案
作为Unicode string
(在 Inno Setup的Unicode版本 – Inno Setup唯一的版本6)实际上使用UTF-16 LE编码,您要做的就是将(Unicode) string
复制到按位的字节数组( AnsiString
).并添加 UTF-16 LE BOM ( FEFF
):
As the Unicode string
(in the Unicode version of Inno Setup – the only version as of Inno Setup 6) actually uses the UTF-16 LE encoding, all you need to do is to copy the (Unicode) string
to a byte array (AnsiString
) bit-wise. And add the UTF-16 LE BOM (FEFF
):
procedure RtlMoveMemoryFromStringToPtr(Dest: PAnsiChar; Source: string; Len: Integer);
external 'RtlMoveMemory@kernel32.dll stdcall';
function SaveStringToUFT16LEFile(FileName: string; S: string): Boolean;
var
A: AnsiString;
begin
S := #$FEFF + S;
SetLength(A, Length(S) * 2);
RtlMoveMemoryFromStringToPtr(A, S, Length(S) * 2);
Result := SaveStringToFile(FileName, A, False);
end;
这与以下内容相反: Inno Setup Pascal脚本-读取UTF-16文件.
这篇关于如何使用Inno Setup保存带有BOM表文件的UTF-16的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文