![]() | ||
This is a NoteTab Clip. Some version of NoteTab is required for use. |
Scans document for lines containing a search term, then builds a new document containing those lines.
Grab the clip code below and do with it what you wish. You can place it within another clip library or in its own library. Name it whatever you wish.
^!Continue Find Lines v1.0^%NL%a NoteTab clip by Joe Barta - HTMLisEasy.com^%NL%^%NL%This clip will scan your document looking for your search phrase. If any lines containing your search phrase are found, they are copied to a new document. Choose between a case-sensitive or case-insensitive search, and chose whether you'd like your search results to include line numbers.^%NL%^%NL%Note - It's meant to search for text line by line, so searching for chunks of text that contain line breaks will probably give unpredictable results. Also, there is no support in this clip for regular expressions... yet.^%NL%^%NL%Click OK to proceed. ; ============================================================================= ; Find Lines v1.0 ; a NoteTab clip by Joe Barta - HTMLisEasy.com ; https://www.htmliseasy.com/notetab/findlines.html ; ; Scans document for lines containing a search term, ; then builds a new document containing those lines. ; Full details and instructions at the web site above. ; ============================================================================= ;kill all variables hanging around in memory ^!ClearVariables ^!Set %searchstring%=^?[Search for] ^!Set %case%=^?[(H=2)Case==_case-insensitive^=0|case-sensitive^=1] ^!Set %linenumbers%=^?[(H=2)Include line numbers?==_yes|no] ^!IF ^$StrSize(^%searchstring%)$ > 0 SKIP_2 ^!Prompt No search term entered. Aborting clip. ^!Goto EXIT ^!SetWordWrap OFF ;is there a carriage return at the end of the doc? ^!Jump TEXT_END ^!If ^$GetCol$ = 1 SKIP_2 ^!Continue I have to insert a carriage return at the end of your document in order to process this clip. You can remove it later if you wish. Press OK to continue. ^!InsertText ^%NL% ^!SetCursor 1:1 ^!Set %foundlines%=0 ^!Set %docpos1%=^$GetDocIndex$ ^!Toolbar New Document ^!Set %docpos2%=^$GetDocIndex$ ^!SetDocIndex ^%docpos1% ^!SetCursor 1:1 ^!Set %currentline%=1 :FINDLOOP ^!If ^%case% = 1 SKIP ^!Find ^%searchstring% TIS ^!If ^%case% = 0 SKIP ^!Find ^%searchstring% TS ^!IF ^$GetSelSize$ = 0 FINISH ^!Select LINE ^!If ^%linenumbers% = no SKIP ^!SetClipboard Line ^$GetRow$:^%TAB%^$GetSelection$ ^!If ^%linenumbers% = yes SKIP ^!SetClipboard ^$GetSelection$ ^!Set %currentline%=^$Calc(^$GetRow$+1)$ ^!SetDocIndex ^%docpos2% ^!Paste ^!Set %foundlines%=^$Calc(^%foundlines%+1)$ ^!SetDocIndex ^%docpos1% ^!SetCursor ^%currentline%:1 ^!Goto FINDLOOP :FINISH ^!SetDocIndex ^%docpos2% ^!SetCursor 1:1 ^!IF ^$GetTextSize$=0 NOMATCH_MESSAGE ELSE TITLE_LINE ^!Goto TITLE_LINE :NOMATCH_MESSAGE ^!DestroyDoc ^!SetDocIndex ^%docpos1% ^!Prompt No lines match ^%searchstring% ^!Goto EXIT :TITLE_LINE ^!IF ^%foundlines%=1 LINE ELSE LINES :LINE ^!Set %line%=line ^!Goto DONE_LINES :LINES ^!Set %line%=lines ^!Goto DONE_LINES :DONE_LINES ^!SetCursor 1:1 ^!InsertText Found ^%foundlines% ^%line% containing ^%searchstring%^%NL% ^!InsertText =======================================================^%NL% ^!SetCursor 1:1 ^!Goto EXIT :EXIT
|
|
|