Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Copy text from file1, Replace text from file2 with text from file1
#1
Solved: 10 Years, 9 Months ago
I want to replace text from file2 with text copied from file1 using QTP. Can anyone help me find my way?
Reply
#2
Solved: 10 Years, 9 Months ago
hi, bjotorres
Here simple code that I wrote.
Code:
'path to file from which text will be copied
fromPath = "c:\from.txt"
'path to file where text should be replaced
toPath = "c:\to.txt"
textThatShouldBeReplaced = "some text to search"

'create File System Object to perform manipulations with files
Set fso = CreateObject("Scripting.FileSystemObject")
'Open text file for reading, copy text from it and close it
Set from_file = fso.OpenTextFile(fromPath, 1)
copiedText = from_file.ReadAll
from_file.Close
'Open text file for writing, replace text in it and close it
Set to_file = fso.OpenTextFile(toPath, 1)
fileText = to_file.ReadAll
to_file.Close
fileText = Replace(fileText, textThatShouldBeReplaced, copiedText, 1, -1, 1)
Set to_file = fso.OpenTextFile(toPath, 2)
to_file.Write fileText
to_file.Close
Maybe it'll help you.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Capture All text from webpage and copy it... mpatra 3 4,902 07-25-2018, 05:33 PM
Last Post: vimlesh
  LearnQuickTestPDF -does not work on just getting the text jloyzaga 0 1,184 02-10-2017, 10:59 AM
Last Post: jloyzaga
  How to edit a text in aParagraph shaan.mishra87@gmail.com 2 2,369 08-26-2016, 04:48 PM
Last Post: shaan.mishra87@gmail.com
  Copy folders from ALM squadri 0 1,692 08-16-2016, 06:23 PM
Last Post: squadri
  How to Verify Static Object Text which is changing Dynamically with Expected Result johnny77 0 3,185 06-25-2015, 11:32 AM
Last Post: johnny77

Forum Jump:


Users browsing this thread: 1 Guest(s)