Jump to content

Stringregexp : how to detect 2 letters in a line


Recommended Posts

Maybe use something like:
nb: Untested.

#include <Array.au3>
#include <File.au3>
Local $aFileRead
_FileReadToArray("C:\AutomationDevelopers\temp.txt", $aFileRead, 0)
_ArrayDisplay($aFileRead, ":: Before ::")
For $i = UBound($aFileRead) - 1 To 0 Step - 1
    If StringRegExp($aFileRead[$i], '(?m)(?|^.*?a.*?e.*$|^.*?e.*?a.*$)\R?') Then _ArrayDelete($aFileRead, $i)
Next
_ArrayDisplay($aFileRead, ":: After ::")
Local $hFileOpen = FileOpen("C:\AutomationDevelopers\Updated.txt", 2)
_FileWriteFromArray($hFileOpen, $aFileRead)
FileClose($hFileOpen)

 

Link to comment
Share on other sites

28 minutes ago, florian2 said:

so far :

#include <file.au3>

$file = FileOpen("C:\AutomationDevelopers\temp.txt", 0)

While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    $line= StringRegExpReplace($line, '(?m)(?|^.*?a.*?e.*$|^.*?e.*?a.*$)\R?', "")
    MsgBox(0,'',$line)
WEnd
FileClose($file)

at least it show correcly line by line the right word, that encouraging. but how to actually delete the line in the file ?

 

 

 

 

How about you just create a new file with the proper output and then delete the old one and rename the new what the old one was named

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

"but no way to get the after with the gui "

Maybe I understood you incorrectly are you saying that the ":: After ::" didn't display after it finished?  I thought you meant you wanted to display the ":: After ::" as it went through the list like your MsgBox in Post 20.  Can you please confirm?

Link to comment
Share on other sites

Actually it work, the only problem is i need to click on the "x" to advance the program manually line by line.

Exemple if there is 10 lines, i need to click 10 times on the "x" of the gui to advance the program. Once i'v clicked 10 times, the result is good. I would like to just have the final result in the updated.txt

 

Link to comment
Share on other sites

Whoops didn't see that that post, then I suppose @florian2 could try:

#include <file.au3>

Local $hFileRead = FileOpen("C:\AutomationDevelopers\temp.txt")
Local $hFileOpen = FileOpen("C:\AutomationDevelopers\Updated.txt", 2)
While 1
    $sFileLine = FileReadLine($hFileRead)
        If @error = -1 Then ExitLoop
    If StringRegExp($sFileLine, '(?m)(?|^.*?a.*?e.*$|^.*?e.*?a.*$)\R?') Then
        ConsoleWrite("Remove: " & $sFileLine & @CRLF)
        ContinueLoop
    Else
        ConsoleWrite("Add: " & $sFileLine & @CRLF)
        FileWrite($hFileOpen, $sFileLine & @CRLF)
    EndIf
WEnd
FileClose($hFileRead)
FileClose($hFileOpen)

 

Link to comment
Share on other sites

This example processes a million line file.  
Most of the run time is taken up displaying the results.

Opt("WinTitleMatchMode", -2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

Local $sFileName = "AAATestFile.txt"

; ========= Create & Display Example test file ==========
If FileExists($sFileName) Then FileDelete($sFileName)
Local $str
For $i = 1 To 1000000 ; 1,000,000 line file
    $str &= $i & "/" & ChrW(Random(97, 102, 1)) & ChrW(Random(97, 102, 1)) & ChrW(Random(97, 102, 1)) & ChrW(Random(97, 102, 1)) & ChrW(Random(97, 102, 1)) & @CRLF
Next
FileWrite($sFileName, $str)
Run("notepad.exe " & $sFileName)
$hWin1 = WinWait($sFileName, "", 0)
WinMove($hWin1, "", 0, 0, @DesktopWidth / 4, @DesktopHeight)
WinSetTitle($sFileName, "", "Unaltered File")
; ====== End of Create & Display Example test file =======

Local $sFileContents = FileRead($sFileName)
FileDelete($sFileName)

FileWrite($sFileName, StringRegExpReplace($sFileContents, '.*(a.*e|e.*a).*\R*', ""))
Run("notepad.exe " & $sFileName)
$hWin2 = WinWait($sFileName, "", 0)
WinMove($hWin2, "", @DesktopWidth / 4, 0, @DesktopWidth / 4, @DesktopHeight)

 

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...