Read the ini file that doesn't have a section?
There is no section in my ini file. It has the following data
com.ibm.rcp.toolbox.admin / toolboxvisibleChild = false com.ibm.collaboration.realtime.community/defaultAuthType=ST-DOMINO-SSO com.ibm.collaboration.realtime.brokerbridge / startBroker = false com.ibm.collaboration.realtime.webapi / startWebContainer = true
I want to use a function.
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section,
string key,string def, StringBuilder retVal,
int size,string filePath);
My problems
- I cannot name the section name in the function because I do not have
- If I give the section name null it returns nothing
- I don't want to use brute force like ReadAllText
+3
source to share
2 answers
Here is the library that the author says supports section keys. I have not tried this library myself.
Or you can just edit the Ini file and add the title / section name at the top right and then delete it once you're done reading.
+2
source to share
Using File.ReadLines , and some LINQs are actually not that bad:
var dict = File.ReadLines("config.txt")
.Where(line => !string.IsNullOrWhiteSpace(line))
.Select(line => line.Split(new char[] { '=' }, 2, 0))
.ToDictionary(parts => parts[0], parts => parts[1]);
var result = dict["com.ibm.rcp.toolbox.admin/toolboxvisibleChild"];
+3
source to share