我有一个文件文件,2000K大小,但是第一行的内容不是我想要的,我想要改一下内容。
原先是“@C!”
改成“@”
请大虾指教。有何良策?多谢多谢了
我用的是TextStream方法

解决方案 »

  1.   

    Private Sub Command2_Click()
        Dim s() As String
        Dim Index As Long
        Dim LineID As Long
        Dim CharID As Long
        Dim sLine As String
        Dim sChar As String
        
        Open App.Path & "\1.txt" For Input As #1
        Index = 0
        Do While Not EOF(1)
            ReDim Preserve s(Index)
            Line Input #1, s(Index)
            Index = Index + 1
        Loop
        Close #1
        
        LineID = 1  '"你要修改的行号"
        CharID = 3 '"你要修改的字符号"
        sChar = "a" '"你要修改的字符"
        
        sLine = s(LineID - 1)
        
        s(LineID - 1) = Left(sLine, CharID) & sChar & Right(sLine, Len(sLine) - CharID)
        Text1.Text = vbNullString
        For Index = 0 To UBound(s)
            Text1.Text = Text1.Text & s(Index) & vbCr
        Next Index
        
        Open App.Path & "\1.txt" For Output As #1
        For Index = 0 To UBound(s)
            Print #1, s(Index) & vbCr
        Next Index
        Close #1
        
    End Sub