Highlighted
Absent Member.
Absent Member.
385 views

Need a script which finds 1line and replace that 1line with 2lines in notepad using QTP

I have a code which finds and replace text in notepad.but i want to replace that text line with 2lines. 2lines is having different text .1st line is possible in my code,but after that i need one more line having text it should in in new line. here is my Code

 

 

 

 

 

 

Const ForReading = 1
Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Users\sd3116\Downloads\20\hhh.txt", ForReading)
strText = objFile.ReadAll
objFile.Close

strNewText = Replace(strText, " 108", " 109")

Set objFile = objFSO.OpenTextFile("C:\Users\sd3116\Downloads\20\hhh.txt", ForWriting)
objFile.WriteLine strNewText

objFile.Close

Msgbox "hi"

0 Likes
2 Replies
Highlighted
Knowledge Partner
Knowledge Partner

Have you tried seperating the 2 lines with a vbCRLF

Replace(strText, "108" & vbCrLf & "109!)

Mark Smith.

0 Likes
Highlighted
Absent Member.
Absent Member.

Hi Mark,

 

thanks for the response, i tried that already.its not working.but my issue is solved by passing a string,which contains 2lines with    & vbCrLf & in between,and passing that string into this Replace method. I tried and its working properly

 

str = "Hello" &vbNewLine& "line2

strNewText2 = Replace(strText, "108", str )

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.