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

What type of error u will get if u have not installed java add in in java project? what is the error name ?

1 Answers   Verizon,


What is the condition or scenario that leads the use of object spy in qtp? (while recording we can get all the properties) then wat leads to use this?

2 Answers   iSoft,


how qtp identify two objects having same name, supose objects are in same page also with same name,specify spl feature.

5 Answers   IGT, Microsoft,


IF THE GUI OF APPLICATION IS CHANGED THEN IS THERE ANY NECISSITY TO CHANGE OR UPDATE OUR TEST SCRIPTS

2 Answers  


what are the critical test cases in crm? tell me atleast 5 critical test cases? what are the critical bug u find out while testing crm domain?

0 Answers  






Hi All, we are using QTP Automation Scripts to test SAP. I recorded QTP Automation Scripts in English-based SAP GUI. Now we have to test a French-based SAP sytem and use the same scripts. The QTP scripts are failing when executed on the French-based SAP System due to Object Recognition Issues. What can we do? Do I re-record the scripts in the French-based SAP system?

0 Answers  


How do you learn the object in QTP?

2 Answers  


Explain how Does Run time data (Parameterization) is handled in QTP?

0 Answers  


HI ALL, HOW WE INSTALL .NET ADD-IN OR JAVA ADD-IN TO THE QTP? PLZ URGENT.ANSWER ME.

2 Answers  


How do i relate the checkbox properties with webelement when checkbox properties are changing on every login to the application

1 Answers   TCS,


Older version QTP is 8.2 and New version QTP is 9.2. My question is, Why it is QTP 9.2, why not 8.3,8.4 .... why it is not something ?

1 Answers  


Pls can anyone give me the entire code for the Keyword driven framework with respect to he Flight Reservation Window in detail with explanation. Pls explain in detail stepwise. Thanks a lot. Pls very urgent?.

0 Answers   Logix,


Categories