. Net (C #)

Source: Internet
Author: User
Whether it is. net Framework set or. net (simplified framework set) can perfectly support XML files, and Microsoft strongly recommends that you replace the INI file with XML files. However, most projects in the industrial control field use the system information configured in the INI file.

In the past, the tunnel management system used the INI file configuration information. To achieve compatibility, we had to use the INI file configuration information in the lower computer. Because the wince platform does not provide the API function getprivateprofilestring for INI file reading, you need to write it on your own. Some time ago, an INI file of the EVC version was provided for reading, later, C # programming was adopted on the wince platform of da66x. Therefore, a C # version of INI reading function is not required.

This is an ini read function that I excerpted based on the original project code.

// Read the INI file;
Private string getprivateprofilestring (string applicationname, string keyname, string default, string filename)
{
String [] iniitems = new string [0];
String inilines;
String iniline;
Int I, J;
Try
{
// Read the INI file;
System. Io. streamreader INIFILE = new system. Io. streamreader (filename, system. Text. encoding. Default );
Inilines = INIFILE. readtoend ();
INIFILE. Close ();
}
Catch
{
Return default;
}
// Separate the lines with carriage returns to get each line
Iniitems = inilines. Split ('');
// Traverse each row
For (I = 0; I <iniitems. getlength (0); I ++)
{
// Find the matching Value
If (iniitems [I]. Trim (). toupper () = '[' + applicationname. Trim (). toupper () + ']')
{
// Search from the next row
For (j = I + 1; j <iniitems. getlength (0); j ++)
{
Iniline = iniitems [J]. Trim ();
If (iniline. length> 0)
{
// If another segment is found, the longer the segment, the default value is returned.
If (iniline [0] = '[' & iniline [iniline. Length-1] = ']') return default;
}
// Remove all spaces
Iniline = iniitems [J]. trimstart (). Replace ("","");
If (iniline. substring (0, math. Min (keyname. Length + 1, iniline. Length). toupper () = keyname. toupper () + "= ")
{
// If key matching is found
Return iniitems [J]. substring (iniitems [J]. indexof ('=') + 1 );
}
}
Return default; // if no matching key is found, the default value is returned.
}
}
Return default; // return the default value.
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.