Jump to content

Find strings in text file


 Share

Recommended Posts

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

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

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...