Guest Posted March 8, 2014 Share Posted March 8, 2014 (edited) Hello, I have a very large script/program and in that script there are lines that have some text sentence. my goal is to create a text document which contains only the lines that have some text sentence (to send that document to someone that will correct the wording...) so i made a script that will read the entire script and will make that document for me. this is what i did: expandcollapse popup#include <File.au3> $Script = @ScriptDir&"\MainScript.au3" $Lines = _FileCountLines($Script) Local $SearchData[7] $SearchData[0] = 6 $SearchData[1] = "GUICtrlSetData" $SearchData[2] = "GUICtrlCreateCheckbox" $SearchData[3] = "_NotifyBox" $SearchData[4] = "GUICtrlSetTip" $SearchData[5] = "GUICtrlCreateListView" $SearchData[6] = "GUICtrlCreateLabel" ConsoleWrite(@CRLF&@CRLF) For $a = 1 To $Lines $Line = FileReadLine($Script,$a) If SearchInString($Line,$SearchData) = 1 Then $Line = StringStripWS($Line, 3) If StringLeft($Line,1) <> ";" Then ConsoleWrite("Line number: "&$a&" , Line: "&$Line&@CRLF) If $a+1 <= $Lines Then For $a2 = $a+1 To $Lines $Line = StringStripWS(FileReadLine($Script,$a2),3) If StringRight($Line,3) = "& _" Then ConsoleWrite("Line number: "&$a2&" , Line: "&$Line&@CRLF) $a = $a2 Else ExitLoop EndIf Next EndIf EndIf EndIf Next ConsoleWrite(@CRLF&@CRLF) Func SearchInString($String,$ToSearchInput) For $a = 1 To $ToSearchInput[0] If StringInStr($String,$ToSearchInput[$a]) > 0 Then Return 1 Next Return 0 EndFunc Also, I found in this script logic errors. But I decided not to fix it because the method is not good.. the problem is that technique which the script based on is simple - it's looks for lines that contain one of these functions: GUICtrlSetData GUICtrlSetTip GUICtrlCreateLabel If it found a line that contains one of these then it will write that line in the document. the problem with this method is that it does not work on all lines. There are lines which contain sentences but not contain one of these functions. and i meen to the line that the sentences are defined as variables. for example, this method will miss this line: $Sentence = "This is a sentence" I thought of another method but I do not know simple way to code it(i can code it but not in simple way). I thought Method that look for a string that start and end with "'" or start and end with '"' and if it found found such string then it will check the length of the string. if the length is more then 9 characters then it will write that line in the new document . I do not know how to do it.Can anyone help? Edited March 8, 2014 by Guest Link to comment Share on other sites More sharing options...
mikell Posted March 8, 2014 Share Posted March 8, 2014 Something to start with $_file = @ScriptDir & "\test.au3" Msgbox(0,"", _Search($_file)) Func _Search($_file) Local $log, $file, $lines $file = FileRead($_file) $lines = StringRegExp($file, '(?m)(^.*)\R?', 3) For $j = 0 to UBound($lines)-1 If StringRegExp($lines[$j], '^[^;]*(".{9,}")|(''.{9,}'')') Then $log &= "line " & $j+1 & " : " & StringStripWS($lines[$j], 3) & @crlf EndIf Next $log &= @crlf Return $log EndFunc Link to comment Share on other sites More sharing options...
Guest Posted March 8, 2014 Share Posted March 8, 2014 (edited) Something to start with $_file = @ScriptDir & "\test.au3" Msgbox(0,"", _Search($_file)) Func _Search($_file) Local $log, $file, $lines $file = FileRead($_file) $lines = StringRegExp($file, '(?m)(^.*)\R?', 3) For $j = 0 to UBound($lines)-1 If StringRegExp($lines[$j], '^[^;]*(".{9,}")|(''.{9,}'')') Then $log &= "line " & $j+1 & " : " & StringStripWS($lines[$j], 3) & @crlf EndIf Next $log &= @crlf Return $log EndFunc Thank you!It fails in many cases(i tested it on 10K lines), but not too much so i can fix the output manually.That's good enough!Thank you!StringRegExp This is very complex function .. Too bad I do not know to use it. Edited March 8, 2014 by Guest Link to comment Share on other sites More sharing options...
orbs Posted March 9, 2014 Share Posted March 9, 2014 another approach: considering that strings in a script are always bound by double-quotes or single-quotes, you can use StringBetween() to get all strings between quotes in the script. Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Link to comment Share on other sites More sharing options...
guinness Posted March 9, 2014 Share Posted March 9, 2014 There is something by Robjong in a question I asked a long time ago about extracting language strings from a custom function of mine. Just search robjong, guiiness language or something similar. '?do=embed' frameborder='0' data-embedContent>> UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
mikell Posted March 9, 2014 Share Posted March 9, 2014 And as a 'sentence' is defined as 'a string bounded with quotes' and you want to skip the commented lines, there are other toys to play with in this nice topic '?do=embed' frameborder='0' data-embedContent>> Link to comment Share on other sites More sharing options...
guinness Posted March 9, 2014 Share Posted March 9, 2014 And as a 'sentence' is defined as 'a string bounded with quotes' and you want to skip the commented lines, there are other toys to play with in this nice topic '?do=embed' frameborder='0' data-embedContent>> Forgot about that one. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now