myspacee Posted October 31, 2008 Share Posted October 31, 2008 hello, anyone can teach me how find multiple similar lines in a text file ? myfile.txt ability aboard acceptable accident accidentally accommodate according account accurate acquire acquit if search for 'acc' list all starting 'acc' words and display them on video on selectable form. Thank you, m. Link to comment Share on other sites More sharing options...
oMBRa Posted October 31, 2008 Share Posted October 31, 2008 search in the help file for string management Link to comment Share on other sites More sharing options...
Richard Robertson Posted October 31, 2008 Share Posted October 31, 2008 Dim $filetext = FileRead("stuff.txt") Dim $mylineswithacc = GetLinesWith($filetext, "acc") For $a = 0 To UBound($mylineswithacc) - 1 MsgBox(0, $a, $mylineswithacc[$a]) Next Func GetLinesWith($text, $line) Return StringRegExp($text, "(?m)^(" & $line & ".*?)$", 3) EndFunc How's that feel? Link to comment Share on other sites More sharing options...
GEOSoft Posted October 31, 2008 Share Posted October 31, 2008 If you are looking to do it in an AuoIt GUI then it will be something like below. $sFile = @ScriptDir & "\Test.txt" GUICreate("Test GUI", 170, 210) $in = GUICtrlCreateInput("", 10, 10, 150, 20) $Edit = GUICtrlCreateEdit("", 10, 40, 150, 160) GUISetState() While 1 $sIn = GUICtrlRead($in) If StringLen($sIn) >= 1 Then $sOut = "" $aRegEx = StringRegExp(FileRead($sFile), "(?i)(?m)^(" & $sIn & ".*)$", 3) If IsArray($aRegEx) Then For $i = 0 To Ubound($aRegEx) - 1 $sOut &= $aRegEx[$i] & @CRLF Next If GUICtrlRead($Edit) <> StringStripWS($sOut, 2) Then GUICtrlSetData($Edit, StringStripWS($sOut, 2)) Else If GUICtrlRead($Edit) <> "" Then GUICtrlSetData($Edit, "") EndIf Else If GUICtrlRead($Edit) <> "" Then GUICtrlSetData($Edit, "") EndIf If GUIGetMsg() = -3 Then ExitLoop Wend George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Richard Robertson Posted October 31, 2008 Share Posted October 31, 2008 What's with the case insensitive expression?And what's with the poorly designed loop? That'll read the file every time even if the file hasn't changed. And I don't see a single sleep in there. Link to comment Share on other sites More sharing options...
GEOSoft Posted November 1, 2008 Share Posted November 1, 2008 What's with the case insensitive expression?I saw nothing to suggest they needed case sensitivity. Its a simple word list.And what's with the poorly designed loop? That'll read the file every time even if the file hasn't changed. And I don't see a single sleep in there. So you have a problem with correcting it? Note the term "it will be something like below". I was using the laptop while laying in bed with no way to even test what I was doing. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Richard Robertson Posted November 1, 2008 Share Posted November 1, 2008 Sorry. I just get carried away some times. Link to comment Share on other sites More sharing options...
myspacee Posted November 1, 2008 Author Share Posted November 1, 2008 thank you both, learn a lot. m. 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