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 

解决方案 »

  1.   

    当作普通文本文件来读写比较简单,没必要用API
    用StreamReader StreamWriter就可以了~
      

  2.   

    [example] 
    uid=sa;  ---->第一个key
    DateFormat=MDY----->第二個 key 读取第一个key的时候,参数section的值为example,参数key的值为uid
    读取第二个.........,..............为example,参数key的值为DateFormat
    明白了吧?
      

  3.   

      UP ~~~学习,,,我感觉有时候尝试去学着怎么调用API 挺好的。
      

  4.   

    -。-||| 這個我當然知道,問題是我怎麼取得 DateFormat 
      

  5.   

    第一个和第二个有什么不同嘛,只要你GetPrivateProfileString的时候第二个参数改成DateFormat 不就行了?
      

  6.   

    你如果section里面的key不知道,key的值也不知道的话,那你自己去实现一个复杂一点的文本查找功能吧。