Jump to content
Sign in to follow this  
myspacee

Find strings in text file

Recommended Posts

myspacee

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.

Share this post


Link to post
Share on other sites
oMBRa

search in the help file for string management

Share this post


Link to post
Share on other sites
GEOSoft

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!"

Share this post


Link to post
Share on other sites
Richard Robertson

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.

Share this post


Link to post
Share on other sites
GEOSoft

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!"

Share this post


Link to post
Share on other sites
Richard Robertson

Sorry. I just get carried away some times.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.