Topic Options
#57953 - 04/12/21 04:24 PM Advance search and replace (replace 2 spaces
sygui Offline
OL Expert

Registered: 11/02/10
Posts: 170
In advance search and replace, how can I replace 2 spaces on line 3 position 220?

Top
#57954 - 04/12/21 04:42 PM Re: Advance search and replace (replace 2 spaces [Re: sygui]
Jean-Cédric Offline
OL Expert

Registered: 10/03/16
Posts: 650
Loc: Québec, Canada
The only way to achieve this would be through a script.
_________________________
♪♫♪♫
99 frigging bugs in my code
99 frigging bugs
Take one down
Code around
127 frigging bugs in my code
♪♫♪♫

Top
#57955 - 04/12/21 04:47 PM Re: Advance search and replace (replace 2 spaces [Re: sygui]
sygui Offline
OL Expert

Registered: 11/02/10
Posts: 170
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)

Top
#57960 - 04/19/21 08:13 AM Re: Advance search and replace (replace 2 spaces [Re: sygui]
Philippe F. Offline
OL Expert

Registered: 09/06/00
Posts: 1968
Loc: Objectif Lune, Montreal, Qc
Replace this line
Code:
s=Replace(s,"",test,4)


with this one
Code:
s=mid(s,1,319) & "Test" & mid(s,322)
_________________________
Technical Product Manager
I don't want to achieve immortality through my work; I want to achieve immortality through not dying - Woody Allen

Top