http://www.cnblogs.com/LevyLiu/archive/2008/04/08/1142565.html
在這找到用正則表達式操作的方法,但這個方法對,用牠程序裡的方法加進去的 section,key才有效,對我本來有的INI文件操作無效(就是讀不出來)。另外一方法調用API函數[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);這個可以實現,但衹能夠先指定一個section,和key才能操作,
現在我是想INI文件裡有多個 key的情況下那怎麼讀取呢?就是以窗體來實現讀完這個,再讀下面一個那要怎麼辦到呢?像這樣的INI
[example]
Connection=uid=sa; ---->讀取這個key 的
DateFormat=MDY ----->再根據需要讀取這個 key
在這找到用正則表達式操作的方法,但這個方法對,用牠程序裡的方法加進去的 section,key才有效,對我本來有的INI文件操作無效(就是讀不出來)。另外一方法調用API函數[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);這個可以實現,但衹能夠先指定一個section,和key才能操作,
現在我是想INI文件裡有多個 key的情況下那怎麼讀取呢?就是以窗體來實現讀完這個,再讀下面一個那要怎麼辦到呢?像這樣的INI
[example]
Connection=uid=sa; ---->讀取這個key 的
DateFormat=MDY ----->再根據需要讀取這個 key
用StreamReader StreamWriter就可以了~
uid=sa; ---->第一个key
DateFormat=MDY----->第二個 key 读取第一个key的时候,参数section的值为example,参数key的值为uid
读取第二个.........,..............为example,参数key的值为DateFormat
明白了吧?