How to read the INI file in C #

xiaoxiao2021-03-06  69

// write INI file [DllImport ( "kernel32")] private static extern bool WritePrivateProfileString (string section, string key, string val, string filePath); // read ini file (character [DllImport ( "kernel32")] private static extern Int getPrivateProfileString (String Section, String Key, String DEF, STRINGBUILDER RETVAL, INT SIZE, STRING FILEPATH);

// Read Ini file (Digital [DLLIMPORT ("Kernel 32")] Private Static Extern Int getPrivateProfileint (String Section, String Key, Int DEF, STRING FILEPATH);

// use system.io; using system.runtime.interopservices; using system.text;

Namespace echoncomponentlibrary {///

/// inIfile summary description. /// public class inifile {private string ffilename;

[DllImport ( "kernel32")] private static extern int GetPrivateProfileInt (string lpAppName, string lpKeyName, int nDefault, string lpFileName); [DllImport ( "kernel32")] private static extern int GetPrivateProfileString (string lpAppName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, int nSize, string lpFileName); [DllImport ( "kernel32")] private static extern bool WritePrivateProfileString (string lpAppName, string lpKeyName, string lpString, string lpFileName);

public IniFile (string filename) {FFileName = filename;} public int ReadInt (string section, string key, int def) {return GetPrivateProfileInt (section, key, def, FFileName);} public string ReadString (string section, string key, string def) {StringBuilder temp = new StringBuilder (1024); GetPrivateProfileString (section, key, def, temp, 1024, FFileName); return temp.ToString ();} public void writeInt (string section, string key, int iVal) {WritePrivateProfileString (section, key, iVal.ToString (), FFileName);} public void WriteString (string section, string key, string strVal) {WritePrivateProfileString (section, key, strVal, FFileName);} public void DelKey (string section, string key ) {WRITEPRIVATEPROFILESTRING (Section, Key, Null, FFileName);} public void delsection (STRING Section) {WritePrivateProfileString (Section, null, null, ffilename);}}}

转载请注明原文地址:https://www.9cbs.com/read-119916.html

New Post(0)