// 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.
}