At this time, I found that cainiao is now learning how to write old birds and referencing old birds.Article
ReferenceHttp://www.pin5i.com/showtopic-8418.html
Code
Using System. runtime. interopservices;
Using System. text;
Namespace INIFILE
{
/// <Summary>
/// Class for reading and writing INI files
/// Call two APIs in kernel32.dll: writeprivateprofilestring and getprivateprofilestring to read and write INI files.
/// The INI file is a text file,
/// Consists of several sections,
/// Under each title with parentheses,
/// Is a number of keywords and their corresponding values)
/// [Section] Key = Value
/// </Summary>
Public Class INIFILE
{
/// <Summary>
/// INI File Name (with Path)
/// </Summary>
Public String Filepath; // Declare the API function for reading and writing INI files
[Dllimport ( " Kernel32 " )]
Private Static Extern Long Writeprivateprofilestring ( String Section, String Key, String Val, String Filepath );
[Dllimport ( " Kernel32 " )] Private Static Extern Int Getprivateprofilestring ( String Section, String Key, String Def, stringbuilder retval, Int Size, String Filepath );
/// <Summary>
/// Class Constructor
/// </Summary>
/// <Param name = "inipath"> INI File Name </Param>
Public INIFILE ( String Inipath)
{
Filepath = Inipath;
}
/// <Summary>
/// Write an INI File
/// </Summary>
/// <Param name = "section"> Section </Param>
/// <Param name = "key"> Key </Param>
/// <Param name = "value"> Value </Param>
Public Void Writeinivalue ( String Section, String Key, String Value)
{
Writeprivateprofilestring (section, key, value, This . Filepath );
}
/// <Summary>
/// Read specified part of the INI File
/// </Summary>
/// <Param name = "section"> Section </Param>
/// <Param name = "key"> Key </Param>
/// <Returns> String </Returns>
Public String Readinivalue ( String Section, String Key)
{
Stringbuilder temp = New Stringbuilder ( 255 );
Int I = Getprivateprofilestring (section, key, "" , Temp, 255 , This . Filepath ); Return Temp. tostring ();
}
}
}