在inifiles编写unicode文本 [英] Write a unicode text at inifiles
问题描述
我如何在.ini文件上写入Unicode字符串Внимание"?我的写作方式:
How i can write the unicode string "Внимание" on a .inifile? how i'm writing:
Escreve := TIniFile.Create(Patch + 'File.ini');
Escreve.WriteString('Informations', 'Patch', ParamStr(0));
文件夹名称为Внимание",并在.inifile处显示????????
The folder name is "Внимание" and at .inifile show ????????
推荐答案
在Windows上, TIniFile
在内部使用Win32 PrivateProfile API(在本例中为 WritePrivateProfileStringW()
(在Delphi 2009及更高版本中). WritePrivateProfileStringA()
完全不支持Unicode,并且 WritePrivateProfileStringW()
仅在INI文件已经存在并且是使用UTF-16 BOM创建的情况下才写入Unicode数据.而是写入ANSI数据.
On Windows, TIniFile
internally uses the Win32 PrivateProfile API (in this case, WritePrivateProfileStringA()
in Delphi 2007 and earlier, and WritePrivateProfileStringW()
in Delphi 2009 and later). WritePrivateProfileStringA()
does not support Unicode at all, and WritePrivateProfileStringW()
writes Unicode data only if the INI file already exists and was created with a UTF-16 BOM, otherwise it writes ANSI data instead.
如果您使用的是Delphi 2009+,请 TMemIniFile
允许您指定 TEncoding 所需字符集的code>
,例如 TEncoding.UTF8
或 TEncoding.Unicode
(UTF-16),例如:
If you are using Delphi 2009+, TMemIniFile
allows you to specify a TEncoding
for the desired charset, such as TEncoding.UTF8
or TEncoding.Unicode
(UTF-16), eg:
Escreve := TMemIniFile.Create(Patch + 'File.ini', TEncoding.UTF8);
Escreve.WriteString('Informations', 'Patch', ParamStr(0));
这篇关于在inifiles编写unicode文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!