如果在c#中要用到ini配置文件那麼就應該要考慮unicode 的問題。
下面介紹一下在c#中使用unicode ini檔的方法。
首先,需要建立乙個unicode的檔案,可以使用如下方法建立:
file.writealltext(filepath, string.empty, system.text.encoding.unicode);
然後,讀寫檔案呼叫系統的api函式,宣告如下:
[system.runtime.interopservices.dllimport("kernel32", charset = charset.unicode)]
public static extern long writeprivateprofilestring(string section, string keyname, string val, string filepath);
[system.runtime.interopservices.dllimport("kernel32", charset = charset.unicode)]
public static extern long getprivateprofilestring(string section, string lpkeyname, string lpdefault, system.text.stringbuilder lpreturnedstring, int nsize, string filepath);
[system.runtime.interopservices.dllimport("kernel32", charset = charset.unicode)]
public static extern int getprivateprofileint(string section, string lpkeyname, int ndefault, string filepath);
delphi中使用配置檔案 ini
unit zs dyjpz inte ce uses windows,messages,sysutils,variants,classes,graphics,controls,forms,dialogs,stdctrls,extctrls,printers,winspool,inifiles typ...
c 建立ini 讀取ini檔案使用記錄
建立 path是檔案目錄 ini檔名 filestream fs new filestream path,filemode.createnew fs.close 自動建立的編碼格式為ansi,測試後無法讀取中文,所以改為手動建立,並修改編碼格式為utf 8 讀取和寫入方式,網上可以找到。注意1 第一...
使用C 操作ini檔案
這個類,封裝了 kernal32.dll 中提供的方法來操作 ini檔案。簡介 這裡建立了乙個類,封裝了 kernel32.dll 中提供的兩個方法,用來操作 ini檔案。這兩個方法是 writeprivateprofilestring 和getprivateprofilestring 需要引用的命...