-
March 12th, 2008, 11:04 PM
#1
reading all key in section in INI file
How can i loop all the key value inside a section in an INI file?
-
March 13th, 2008, 08:19 AM
#2
Re: reading all key in section in INI file
How are you reading the INI file to begin with?
-
March 13th, 2008, 11:59 AM
#3
Re: reading all key in section in INI file
Originally Posted by nelo
How are you reading the INI file to begin with?
i just want to read from certain section... i know there is a function GetPrivateProfileString(), but it need to specify the exact section and keyname... what about i wanna read out all key and values inside the section?
-
March 13th, 2008, 12:14 PM
#4
Re: reading all key in section in INI file
I may be wrong but seems to be a Windows API function and not available in the .NET Framework directly. At least not in .NET 2.0. If you want to take that approach there is also the GetPrivateProfileSection function that will give you all the key value pairs in a section. Are you planning to use platform invoke to access the native Windows API?
-
March 13th, 2008, 12:17 PM
#5
Re: reading all key in section in INI file
If you didn't have access to an INI parser I would write one that read the data into a:
Dictionary<string header, Dictionary<string key, string value>>
Then you can find whatever key value you needed very easily.
As far as the parsing itself, that's really easy to do, in fact, it's probably already done on codeproject.com or somewhere similar.
-
March 13th, 2008, 12:25 PM
#6
Re: reading all key in section in INI file
Originally Posted by opedog
If you didn't have access to an INI parser I would write one that read the data into a:
Dictionary<string header, Dictionary<string key, string value>>
Then you can find whatever key value you needed very easily.
As far as the parsing itself, that's really easy to do, in fact, it's probably already done on codeproject.com or somewhere similar.
Very good point. This would probably be a good approach if you are likely to want the same functionality in other projects/development work. You will have to weigh up the two options and decide which is more flexible/easy for what you need. OpeDog's approach is really good if you will need to access other sections of the file.
-
March 13th, 2008, 09:46 PM
#7
Re: reading all key in section in INI file
i just wanna read out the key on the particular section of the ini files...
what is the different between GetPrivateProfileSection and GetProfileSection?
-
March 14th, 2008, 02:50 AM
#8
Re: reading all key in section in INI file
Originally Posted by lsy
i just wanna read out the key on the particular section of the ini files...
what is the different between GetPrivateProfileSection and GetProfileSection?
GetProfileSection is used for specifically for the win.ini file. For other INI files you have to use GetPrivatProfileSection.
-
March 24th, 2008, 11:01 PM
#9
Re: reading all key in section in INI file
Originally Posted by nelo
GetProfileSection is used for specifically for the win.ini file. For other INI files you have to use GetPrivatProfileSection.
If i don't specify the section(AppName) name but only specify the key... would it be able to search whole file and return me the value of the key?
i try
GetPrivateProfileString(null, sKey, "", temp, 255, @sINIFile);
i read from MSDN is should be able to return...
pleae advice...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|