各位大虾:我想将一个文件指定行的内容删除后成为另外一个文件。
例如,原文件如下:
    Hello,My name is Robin.
    How are you ?
    This is a test file.
如删除第二行,新文件为
    Hello,My name is Robin.
    This is a test file.
该怎样实现,一个很菜的问题了,可我就是不会,还望大家指点!谢谢!!!

解决方案 »

  1.   

    dim tmp as string
    dim i as longopen "c:\1.txt" for input as #1
    open "c:\2.txt" for output as #2
         i=1
         do while not eof(1)
            line input #1,tmp
            if i<>你指定的行 then
               print #2,tmp
            end if
            i=i+1
         loop
    close #2
    close #1
      

  2.   

    谢谢!另外我得判断一下从哪行开始计数,如输入(How are you ?,1)那么就是删除整个文件的第三行。我的代码是这样写的,请帮忙分析一下错在哪里:
        Dim myLine As String  '读入的文件行
        Dim intDelete As Integer   '开始计数的行号
        Dim intRow As Integer      '要删除的行号
        Dim strName As String      '碰到此行开始计数
        intDelete = 1
        Open strOldFile For Input As #1
        Open strNewFile For Output As #2
        
        Do While Not EOF(1)
            Line Input #1, myLine
            If myLine <> strName Then
                Print #2, myLine
            Else
                If intDelete = intRow Then
                    Line Input #1, myLine
                    intDelete = intDelete + 1
                Else
                    Print #2, myLine
                End If
            End If
        Loop
                
        Close #2
        Close #1
      

  3.   

    这段代码我有些不太明白            If intDelete = intRow Then
                    Line Input #1, myLine
                    intDelete = intDelete + 1
                Else
                    Print #2, myLine
                End If===================================================
        Dim myLine As String  '读入的文件行
        Dim intDelete As Integer   '开始计数的行号
        Dim intRow As Integer      '要删除的行号
        Dim intLine As Long        '当前行号
        Dim strName As String      '碰到此行开始计数
        intDelete = 1
        Open strOldFile For Input As #1
        Open strNewFile For Output As #2
        
        intLine = 1
        Do While Not EOF(1)
            Line Input #1, myLine
            If trim(myLine) <> trim(strName) Then
                Print #2, myLine
            Else
                intRow=intLine
            End If
            intLine=intLine+1
        Loop
                
        Close #2
        Close #1
      

  4.   

    Line Input #文件号,字符串变量
    该语句可以一次读入1行,从源文件1行1行拷贝到目标文件,判断某行不要,就不写入目标文件,删除源文件,该目标文件到源文件。