Jump to content
Sign in to follow this  
gil900

Need to extract anything that is text from another script

Recommended Posts

gil900

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:

#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 by gil900

Share this post


Link to post
Share on other sites
mikell

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

Share this post


Link to post
Share on other sites
gil900

 

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 by gil900

Share this post


Link to post
Share on other sites
orbs

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.

Share this post


Link to post
Share on other sites
guinness

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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
guinness

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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×