1 读入字符串变量strTemp
2 strTemp = replace(strTemp,str1,str2)
3 将变量写回文件

解决方案 »

  1.   

    to of123:
    问题在写回文件的时候,会在后面显示三个小方块,why?print #2 strTemp我用put #2 strTemp 也不行,在字符前会有小方块。
    如何解决,各位老大。
    Function ChangeStr(spp$, tpp$, PFile$)'spp为被替代的内容
    'Tpp为要写入的内容
    'PFile为要处理的文本类文件
    Dim Dsdfg$, I&, II&, tempStrOpen PFile For Input As #1
    Do While Not EOF(1)
       I = Seek(1)
       II = 0
       Line Input #1, Dsdfg
       If InStr(Dsdfg$, spp) Then
          tempStr = Replace(Dsdfg$, spp, tpp)
          tempStr = Left(tempStr, Len(tempStr))
          
       'Open PFile For Append As #2
       Open PFile For Binary As #2
       Seek #1, I
       
          Put #2, , tempStr
       
          Close #2
          Exit Do
       End If
    Loop
    Close #1End Function
      

  2.   

    上面代码错了
    Open PFile For Input As #1
    Do While Not EOF(1)
       I = Seek(1)
       II = 0
       Line Input #1, Dsdfg
       If InStr(Dsdfg$, spp) Then
          tempStr = Replace(Dsdfg$, spp, tpp)
          tempStr = Left(tempStr, Len(tempStr))
          
          Exit Do
       End If
    Loop
    Close #1
       
    'Open PFile For Append As #2
       Open PFile For Binary As #2
       Seek #1, I
       
          Put #2, , tempStr
       
          Close #2