先把它全部读取到一String
对那String的字符进行替换
再写入文件

解决方案 »

  1.   

    Dim strAll As String
        Dim strLine As String
        
        Open "SourceFileName" For Input As #1
        Do While Not EOF(1)
            Line Input #1, strLine
            strLine = Replace(strLine, "abc", "efg")
            strAll = strAll & strLine & vbCrLf
        Loop
        Close #1
        
        Open "DestinationFileName" For Output As #2
        Print #2, strAll
        Close #2
      

  2.   

    这样读写比较好:读取:
    Dim TempFile As Long
    Dim LoadBytes() As ByteTempFile=FreeFile
    Open 文件名 For Binary As #TempFile
    Redim LoadBytes(1 To Lof(TempFile)) As Byte
    Get #TempFile,,LoadBytes
    Close TempFileText1.Text=StrConv(LoadBytes,vbUniCode)写入:
    Dim TempFile As Long
    Dim SaveBytes() As ByteSaveBytes=StrConv(Text1.Text,vbFromUniCode)TempFile=FreeFile
    Open 文件名 For Binary As #TempFile
    Put #TempFile,,SaveBytes
    Close TempFile
      

  3.   

    我想要一个比较简单的方法,但是replace(abc.txt,"abc","efg")我怎么也替换不来.
    谁能再帮帮我?
      

  4.   

    还有一个办法。
    你可以这样做。
    用left取出text的每一位,然后加其你想得到最后数值的ascii码
    然后再转回字符就ok

    这有一个例子
    '根据用户输入生成不定序列号,其值为S
    s2 = ""
    S = ""
    s1 = ""
    If txtuse.Text = "" Then
    MsgBox "请输入用户名!", , "提示"
    Else
    s2 = txtuse.Text
    For I = 1 To Len(txtuse.Text)
         A = Left(txtuse.Text, I)
         b = Right(A, 1)
         m = Asc(b) - I
    100:
    If m >= 65 And m <= 90 Then
         S = S + Chr(m)
    Else
          If m < 65 Then
              m = m + I
           Else
               m = m - I
           End If
       GoTo 100
     End If
    Next
    s1 = S
    '生成固定长度
    If Len(S) < 10 Then
     For j = 1 To 10 - Len(s1)
      d = Left(s1, I)
         e = Right(d, 1)
         k = Asc(e) - j
    104:
    If k >= 65 And k <= 90 Then
         S = S + Chr(k)
    Else
          If k < 65 Then
              k = k + j
           Else
               
               k = k - j
           End If
       GoTo 104
     End If
     Next
    End If
    txtserial.Text = S