I have a script that searches a specific file and finds/replaces a string of text. I believe it is choking on some special charachters in that line of text.
I suspect the gremlin is in the assignment of the "strOld" variable.
I am missing quotes or something simple. I just can't see it.
Note that our script is finding the file correctly and is able to open it. It just can't find that specific line of txt. If I simplify it and just look for "pdfviewer", I can find/replace it with no problem. It is just choking on the full line with all of the special charachters.
Here is the section of vbs code I am struggling with. What am I missing? :
-----------------
Function SearchReplaceFile(sTargetFileName)
strOld = " <!-- <viewer type=""Controls.PDFViewer, gui.viewers"" /> -->"
WScript.Echo "Looking for " + strOld
strNew = "<viewer type=""Controls.PDFViewer, gui.viewers"" />"
WScript.Echo "Replacing with " + strNew
Set objFile = oFSO.OpenTextFile(sTargetFileName, 1)
strText = objFile.ReadAll
objFile.Close
If ( InStr(strText,strNew) = 0 ) Then
WScript.Echo "Found text to replace in " + sTargetFileName
strNewText = Replace(strText,strOld,strNew)
Set objFile = oFSO.OpenTextFile(sTargetFileName, 2)
objFile.WriteLine strNewText
objFile.Close
Else
WScript.Echo "Didn't find text to replace in " + sTargetFileName
End If
End Function
-----------------
The actual line we are looking for is :
<!-- <viewer type="Controls.PDFViewer, gui.viewers" /> -->
We want to replace it with :
<viewer type="Controls.PDFViewer, gui.viewers" />