Apologies if this information is elsewhere in the forum, I couldn’t find it.
I’d like to know how to search for a section of text in a file that starts with a certain phrase and ends with another and delete them and everything in between.
dim s as string="BEGIN YOUR TEXT"
dim t as string="END OF TEXT"
x=instr(ta.text,s)
y=instr(x,ta.text,t)
if x>0 and y>x then
ta.selstart=x
ta.sellenght(=y-x)+len(t)
ta.seltext=""
dim rx as new RegEx
rx.SearchPattern = "#beginning phrase\\b[\\s\\S]*#ending phrase\\b"
rx.ReplacementPattern = ""
rx.Options.ReplaceAllMatches = true
rx.Options.Greedy = false
s = rx.Replace( s )
Dave, you didn’t define all your variables, so I wasn’t sure how to proceed with a test.
Kem, I tried your method but couldn’t get it to work. Here’s my code.
[code] Dim dlg As New OpenDialog
dlg.ActionButtonCaption = “Select”
dim f as FolderItem
Dim t as TextInputStream
dlg.Title = “Choose File”
Dim docType as New FileType
docType.Name = “Files”
dlg.Filter=docType
dlg.MultiSelect=True
dlg.InitialDirectory=SpecialFolder.Desktop
f = dlg.ShowModal
If f = Nil Then
return
End
t = TextInputStream.Open(f)
dim s as string
dim rx as new RegEx
rx.SearchPattern = “#Start\b[\s\S]*#Finish\b”
rx.ReplacementPattern = “”
rx.Options.ReplaceAllMatches = true
rx.Options.Greedy = false