Let's say I am searching for the words 'MAIN' and 'NEARBY' and the maximum distance of the two words is 2:
- when a text file contains 'MAIN' in the lines 1, 10 and 20 and 'NEARBY' is in the lines 5, 15 and 25, the searching would have a negative result
- when a text file contains 'MAIN' in the lines 1, 10 and 20 and 'NEARBY' is in the lines 5, 15 and 18, the searching would return line 20 as a hit
I could search for the MAIN only and scan again for NEARBY seperately, but it would be slower than doing everything in a big loop.
I started a simple code but it is to simple (and fails in many cases)...
Code: Select all
String.s=ReplaceString("This is a test.Here's a simple line.And another line.A line with 'xxx'.A line with 'hehello',this should be found.And so on.And so on.Okay, one more line.And a last hello",".",#CRLF$)
String=LCase(String); just for testing to ignore case issues for the moment...
Main.s="hello"
;Main.s="hehe"
Near.s="line"
*Memory.Character=@String; Buffer
*Main.Character=@Main; Main (never empty)
*Near.Character=@Near; Nearby
*ScanMain.Character
*ScanNear.Character
NearDistance=2; maximum ine distance
LineCount=1
If Bool(*Near\c); Nearby searching...
Repeat
c=*Memory\c
If c=#CR
LineCount+1
EndIf
If ScanMain
If c=*ScanMain\c;
;Debug "ok "+Chr(c)
If c=0
FoundMain=LineCount
Debug "FOUND MAIN at the end"
Else
*ScanMain+SizeOf(Character)
EndIf
ElseIf *ScanMain\c
ScanMain=#Null
Else
If FoundNear>=LineCount-NearDistance
Debug "B I N G O"
EndIf
Debug "FOUND MAIN "+c+"/"+*ScanMain\c+" at line "+LineCount
ScanMain=#Null
FoundMain=LineCount
EndIf
EndIf
If ScanNear
If c=*ScanNear\c;
;Debug "ok "+Chr(c)
If c=0
FoundNear=LineCount
Debug "FOUND at the end"
Else
*ScanNear+SizeOf(Character)
EndIf
ElseIf *ScanNear\c
ScanNear=#Null
Else
If FoundMain>=LineCount-NearDistance
Debug "B I N G O"
EndIf
Debug "FOUND NEAR "+c+"/"+*ScanNear\c+" at line "+LineCount
ScanNear=#Null
FoundNear=LineCount
EndIf
EndIf
If c
If c=*Main\c
*ScanMain=*Main+SizeOf(Character)
Debug "Start Main at line "+LineCount
ScanMain=#True
EndIf
If c=*Near\c
*ScanNear=*Near+SizeOf(Character)
Debug "Start Near at line "+LineCount
ScanNear=#True
EndIf
Else
Break
EndIf
*Memory+SizeOf(Character)
ForEver
Debug "*"
Else
Debug "No Nearby find needed..."
EndIf


