打个比方,下面2段配置信息,[]内是标题,标题下面是字段,假如2个标题下面的字段名有一样的,怎么判断修改他们,
2个配置段用一个空格格开,这只是个例子,配置要比这个多,怎么才能方便快速的修改某个标题下的配置字段呢
求助....给出例子代码最好,谢谢了先,
[ZAlternatesItem]
Bg_Type_H = 2
Bg_Type_Std = 0
Bg_Stretch_H = 5
Bg_Opacity_H = 100
Bg_Opacity_Std = 0
Padding_Left = 4
Padding_Right = 4
Padding_Top = 4
Padding_Bottom = 4[ZAppInfoArea]
Bg_Type_Std = 2
Bg_Stretch_Std = 5
Bg_Color_Std = 0
Bg_Opacity_Std =100
Border_Type_Std = 0
Padding_Left = 6
Padding_Right = 6
Padding_Top = 5
Padding_Bottom = 5
Spacing_H1 = 9
Spacing_H2 = 3

解决方案 »

  1.   

    两个HashTable搞定,先读,后删,再写!只有这么整!
      

  2.   

    INI格式已过时...能改就改成XML...否则要么调用Win32API要么就当成TXT逐行剖析...
      

  3.   

    要快速的话还是要用xml的,这样会比较快。
      

  4.   


    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;
    using System.IO;
    namespace myini
    {
        public class Ini
        {
            [DllImport("kernel32.dll")]
            private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
            [DllImport("kernel32.dll")]
            private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
            private static string path;
            public Ini()
            {
                path = Application.ExecutablePath;
                FileInfo fi = new FileInfo(path);
                path = fi.Directory.ToString();
            }        public static void IniWriteValue(string Section, string m_Key, string Value, string filepath)
            {          
                WritePrivateProfileString(Section, m_Key, Value, path + filepath);
            }
            public static string IniReadValue(string Section, string m_Key, string filepath)
            {
                StringBuilder temp = new StringBuilder();
                temp.Capacity = 65535;
                int i = GetPrivateProfileString(Section, m_Key, "", temp, temp.Capacity, path + filepath);
                return temp.ToString();
            }
        }
    }
    用这个类吧,然后配合Dictoinary或者HashTable