using System.Runtime.InteropServices;
using System.Text;public class IniFile { public string path;    //INI文件名 [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);
//声明读写INI文件的API函数      public IniFile(string INIPath) { path = INIPath; }//类的构造函数,传递INI文件名 public void IniWriteValue(string Section,string Key,string Value) { WritePrivateProfileString(Section,Key,Value,this.path); }//写INI文件          public string IniReadValue(string Section,string Key) { StringBuilder temp = new StringBuilder(255); int i = GetPrivateProfileString(Section,Key,"",temp,255,this.path); return temp.ToString(); }//读取INI文件指定 }

解决方案 »

  1.   

    然后
    IniFile test=new IniFile(@"c:\a\b.ini");
    string s1=test.IniReadValue("LOC","Item1");
    现在s1的值为"1,2"再s1.split(",")[1]这就是2了
      

  2.   

    http://search.csdn.net/Expert/topic/1679/1679357.xml?temp=.3655359
      

  3.   

    怎么取出每个Item 逗号之 前 的值?  1  1 1 2  11  10  8  9  9  2  3
      

  4.   

    比较笨的办法:
    FileStream myf=new FileStream("f:\\zhu.ini",FileMode.Open,FileAccess.Read);
    StreamReader myreader=new StreamReader(myf); string a="";//存放结果

    string s="";
    string k="";
    int pos=0;
    s=myreader.ReadLine();
    while(s!=null)
    {

       s=s.Trim();
    if(s.Substring(0,4)=="Item")
    {
    pos=s.IndexOf("=");

    if(k=="")
    {
    a=s.Substring(pos+1,s.Length-1-pos);

    }
    else
    {
    k=s.Substring(pos+1,s.Length-1-pos);
    a=a+","+k;
    }
    }   
     s=myreader.ReadLine(); }
                  
                 string []box1=a.Split(',');//转成数组

    //show result
    for(int i=0;i<box1.Length;i++)
    {             this.listBox1.Items.Add(box1[i].ToString());
    }             //show result
    for(int i=1;i<box1.Length;i=i+2)
    { this.listBox2.Items.Add(box1[i].ToString());
    }
      

  5.   

    INI Class for .NET - C# Programming http://www.codeproject.com/csharp/aejw_ini_class.asp
      

  6.   

    C# Ini访问类http://hubdog.csdn.net/UpdateList/ul20030726.htm