I want to open a text file and then search some specified
text in it and then replace that text with some other text
i found that text in .txt but do not know how to replace
that text can any body help me. if possible put the code
for qtp

Answers were Sorted based on User's Feedback



I want to open a text file and then search some specified text in it and then replace that text wi..

Answer / rico

Const ForReading = 1, ForWriting = 2
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("c:\working\replace.txt",
ForWriting, True)
f.Write "QTP QTP RFT QTP QTP RFT QTP QTP"
Set f = fso.OpenTextFile("c:\working\replace.txt",
ForReading)
ReadAllTextFile = f.ReadAll
newText = Replace( ReadAllTextFile, "QTP", "QTPRO")
Set textFile = fso.OpenTextFile
( "C:\working\replace.txt", ForWriting )
textFile.WriteLine newText
f.Close

Is This Answer Correct ?    12 Yes 4 No

I want to open a text file and then search some specified text in it and then replace that text wi..

Answer / venki

Function Replacestring(filepath,find_string,replace_string)

Const ForReading = 1
Const ForWriting = 2

Dim obj,notepad,myline,newText
Set obj = CreateObject("scripting.FileSystemObject")
Set notepad=obj.OpenTextFile(filepath,ForReading)
Do Until notepad.AtEndOfStream
myline = notepad.readall
loop
msgbox myline
newText = Replace(myline ,find_string,replace_string)
Set notepad = obj.openTextFile(filepath, ForWriting )
notepad.WriteLine newText
notepad.Close
msgbox newText
end function
Call Replacestring("C:\New Folder\fade to
black.txt","me","you")'>mention your file path,string to
find,replacing string.

Is This Answer Correct ?    7 Yes 2 No

Post New Answer

More QTP Interview Questions

in one page we have 100 links i have to click the 99th link how can i click the 99th link.

4 Answers   GK Technologies, IBM,


How can you handle exceptions in qtp?

0 Answers  


What is the exact difference between QTP and RFT ?

2 Answers   CTS,


How u call functions in QTP

5 Answers   Lehman Brothers,


Hi, How to give drop down values as input [Variable] from data table in QTP? If u know share with me.

3 Answers  






I have application it is one digital clock with all minutes and seconds. you have to identify the time to verify weather the time displayed is correct time or not? How do you automate this scenario?

2 Answers   TCS,


write a script for allinterview-submit Question first we've to select Choose Category,second select Sub- Category(Which is comes in to runtime)third select Question Type.for that give some descriptive and vb script

0 Answers  


What is the use of low level recording? How does it useful?

1 Answers  


What is the difference between Mandatory and BaseFilter Properies..Anybody please answer me..Thanks in Advance

3 Answers   BirlaSoft,


How does Parameterization and Data-Driving relate to each other in QTP?

2 Answers  


What is a Web Table?

5 Answers   Kanbay,


How can we do Data driven testing Using For loop in QTP?

2 Answers  


Categories