谢谢代码。
谢谢!!!!!!

解决方案 »

  1.   

    试试正则表达式吧~~但是不知道在vb里怎么写。我在asp里用过,也许在MSDN上能查到。
    先用FSO把ini文件读入。
    dim objRegExp as object
    Set objRegExp=new RegExp
    objRegExp.IgnoreCase =true
    objRegExp.Global=Trueobj
    RegExp.pattern="(\[)(.+?)(\])"
    然后用$2代替[]中间的部分。
      

  2.   

    Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
    Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As LongFunction ReadConfig(AppName As String, StrKey As String) As String
        Dim StrBuff As String
        Dim Xpos As Integer
        StrBuff = String(255, Chr(0))
        GetPrivateProfileString AppName, StrKey, "ERROR", StrBuff, 255, AddBackSlash(App.path) & "config.ini"
        ReadConfig = Trim(Left(StrBuff, InStr(StrBuff, Chr(0)) - 1))
    End FunctionFunction WriteConfig(AppName As String, StrKey As String, StrValue As String) As String
        WritePrivateProfileString AppName, StrKey, StrValue, AddBackSlash(App.path) & "config.ini"
    End FunctionFunction AddBackSlash(lzPath As String) As String
        If Right(lzPath, 1) <> "\" Then AddBackSlash = lzPath & "\" Else AddBackSlash = lzPath
    End Function
      

  3.   

    Public Function RenameSection(ByVal FileName As String, ByVal SectionName As String, ByVal NewSectionName As String) As Integer
    'Renames a section in a given INI file.
    'Function returns 1 if successful and 0 if unsuccessful
    Dim TopKeys As String
    Dim BotKeys As String
    Dim Looper As Integer
    Dim InputData As String
    Dim InZone As Boolean
    Dim Key1 As String, Key2 As String
    If Dir(FileName) = "" Then MsgBox FileName & " not found.", vbCritical, "File Not Found": Exit Function
    If Not SectionExists(FileName, SectionName) Then MsgBox "Section, " & SectionName & ", Not Found. ~(RenameSection)" & vbCrLf & "Verify spelling and capitilization is correct.  Case-sensative.", vbInformation, "Section Not Found.": RenameSection = 0: Exit Function
    If SectionExists(FileName, NewSectionName) Then MsgBox NewSectionName & " allready exists.  ~(RenameSection)", vbInformation, "Duplicate Section": RenameSection = 0: Exit Function
    Open FileName For Input As #4Do While Not EOF(4)
        Line Input #4, InputData
        If InZone Then
            If BotKeys = "" Then BotKeys = InputData Else BotKeys = BotKeys & vbCrLf & InputData
            If EOF(4) Then
                Close #4
                Kill FileName
                Open FileName For Append As #5
                If TopKeys <> "" Then Print #5, TopKeys
                Print #5, "[" & NewSectionName & "]" & vbCrLf & BotKeys
                Close #5
                RenameSection = 1
                Exit Function
            End If
        Else
            If InputData = "[" & SectionName & "]" Then
                InZone = True
            Else
                If TopKeys = "" Then TopKeys = InputData Else TopKeys = TopKeys & vbCrLf & InputData
            End If
        End If
    Loop
    Close #4
    End Function
      

  4.   

    不对吧。我是想知道某个ini文件里
    有多少个section,也就是有多少个[];
    每个section里的字符串[。],是什么,能写下来。对具体section中key的读写已经没有问题。请再看看!
    谢谢!!!
      

  5.   

    一般来说,我喜欢将它当成一个TXT文件来分析,因为section是带“[]”的,而其中的字符串是带“=”号的。这样不会存在难度吧?
      

  6.   

    qingming81(晴明) 你能给一段代码吗?
    谢谢你。
    对文本文件的操作,
    我是速成新手
    谢谢