I have this script. how can I do: If the line begins with Header, replace " " (2 spaces) at position 320 by the word test
' Script to perform search and replace, but only on lines starting and ending by *.
' Created by: Raphaël Lalonde Lefebvre, Objectif Lune, 05/10/2012 (D/M/Y)
' Variables declarations.
Option Explicit
const cRead=1, cWrite=2, cAppend=8
dim FSO
set FSO=CreateObject("Scripting.FileSystemObject")
dim fileInput, fileOutput
dim sTempPath, sTempName
dim s
dim stringtosearch
dim stringtoreplace
' Open the current input file, create a temporary output file.
Set fileInput=FSO.OpenTextFile(Watch.GetJobFilename, cRead)
sTempPath=FSO.GetFile(Watch.GetJobFilename).ParentFolder.Path
sTempName=FSO.GetTempName
Set fileOutput=FSO.GetFolder(sTempPath).CreateTextFile(sTempName)
' Loop through the lines. Do a search and replace, but only if the line starts and
' end with *.
do while not (fileInput.AtEndOfStream)
s = fileInput.ReadLine()
if ((mid(s, 1, 6) = "Header")) then
s = Replace(s," ", "test", 4)
end if
fileOutput.WriteLine(s)
loop
' Close the files.
fileInput.Close
fileOutput.Close
' Have the temporary output file becomes the current job file.
FSO.DeleteFile Watch.GetJobFilename, true
FSO.MoveFile sTempPath+"\"+sTempName, Watch.GetJobFileName
Edited by sygui (04/13/21 08:16 AM)