可不可不要这么样徘徊在目光内 / 你会察觉到我根本寂寞难耐 / 即使千多百个深夜曾在梦境内 / 我有吻过你这毕竟并没存在 / 人声车声开始消和逝 / 无声挣扎有个情感奴隶 / 是我多么的想她 / 但我偏偏只得无尽叹谓 / 其实每次见你我也着迷 / 无奈你我各有角色范围 / 就算在寂寞梦内超出好友关系 / 唯在暗里爱你暗里着迷 / 无谓要你惹上各种问题 / 共我道别吧别让空虚使我越轨 /

原创]使用QTP对TXT文件进行读取和写入

上一篇 / 下一篇  2007-08-22 12:32:32 / 个人分类:测试代码

2007-08-19 13:44:18 / 个人分类:QTP

c:\test.txt

原来是
####
orcal=true
####

####
#MySQL=true
#####

改为
####
#orcal=true
####

####
MySQL=true
#####

 

使用函数:

Function Replace_str(oldstr,newstr)
Set fso = CreateObject("scrīpting.FileSystemObject")
Set MyFilebak = fso.CreateTextFile("c:\testbak.txt", True)
MyFilebak.close
Set CreFile = fso.GetFile("c:\test.txt")
CreFile.Copy ("c:\testbak.txt")
Set MyFilebak=fso.OpenTextFile("c:\testbak.txt", 1, false)
Set theFile = fso.OpenTextFile("c:\test.txt", 2, True)
Do While MyFilebak.AtEndOfStream <> True
      retstring = MyFilebak.ReadLine
          If retstring=oldstr Then
                  theFile.WriteLine newstr

                  else
                            theFile.WriteLine retstring
          End If

   Loop
   MyFilebak.close
Set DelFile = fso.GetFile("c:\testbak.txt")
DelFile.Delete
   theFile.Close
   ReadEntireFile = retstring
End Function

Call Replace_str("#orcal=true","orcal=true")
Call Replace_str("MySQL=true","#MySQL=true")

 


TAG: 测试代码

 

评分:0

我来说两句

Open Toolbar