Jump to content

Check String Exist in Txt File Every 5min


Recommended Posts

Hi guys, really need your help. How can i check every 5 min if my text file include String "Markus". Btw i need this function to run on my Logs file that are updated whenever some event is triggered (logs appear in same txt file). So i did test some codding to test isit possible.

But somehow, it only detect for the 1st time String check, and keep coming the same output every time, it didnt check/read on the current txt file that has been updated.

For this purpose i update txt file manually so i put String "Markus" and check, and try to remove it agn.

Here is my code:

 

$file = FileOpen("c:\hello.txt", 0)
$read = FileRead($file)

func _CheckString()
   If StringInStr($read, "Markus") Then
      $position = StringInStr($read, "Markus")
      MsgBox(0,"","Alert Found - Logs Line No "&$position, 5)
      FileClose($file)
   Else
      MsgBox(0,"","No Alert found", 5)
      FileClose($file)
   EndIf
EndFunc

$Mins = 0.5 ; i change to fewer min for testing purpose
$Timer = TimerInit()

While 1
    If TimerDiff($Timer) > ($Mins * 60000) Then ; count per minute multiplied by 60sec.
       _CheckString()
       ConsoleWrite("30 Sec have passed!" & @CRLF) ; console to see if its running.
       $Timer = TimerInit()
    EndIf
 WEnd

 

Edited by levila
add more information
Link to post
Share on other sites
29 minutes ago, levila said:

But somehow, it only detect for the 1st time String check, and keep coming the same output every time

close the file in the function

FileClose($file)

but not attempt to open and read again when time is up the second time around. should place these in the func

$file = FileOpen("c:\hello.txt", 0)
$read = FileRead($file)

 

Edited by zeenmakr
Link to post
Share on other sites

I would also change the part that you use to execute the function every 5 minutes:

$Mins = 0.5 ; i change to fewer min for testing purpose
$Timer = TimerInit()

While 1
    If TimerDiff($Timer) > ($Mins * 60000) Then ; count per minute multiplied by 60sec.
       _CheckString()
       ConsoleWrite("30 Sec have passed!" & @CRLF) ; console to see if its running.
       $Timer = TimerInit()
    EndIf
 WEnd

to

AdlibRegister("_CheckString", 30000)

And if you do need any kind of console or log output, put it into the checkstring funtion:

func _CheckString()
    Consolewrite("Entering at the function at " & @HOUR & ":" & @MIN & @CRLF)
    
   If StringInStr($read, "Markus") Then
      $position = StringInStr($read, "Markus")
      MsgBox(0,"","Alert Found - Logs Line No "&$position, 5)
      FileClose($file)
   Else
      MsgBox(0,"","No Alert found", 5)
      FileClose($file)
   EndIf
EndFunc

 

Link to post
Share on other sites

You might use in StringInStr the 'occurence' parameter and increment it
Something like this (untested)

func _CheckString()
    Local Static $occ = 1
    Consolewrite("Entering at the function at " & @HOUR & ":" & @MIN & @CRLF)
    
   If StringInStr($read, "Markus", 0, $occ) Then
      $position = StringInStr($read, "Markus", 0, $occ)
      $occ += 1
      MsgBox(0,"","Alert Found - Logs Line No "&$position, 5)
      FileClose($file)
   Else
      MsgBox(0,"","No Alert found", 5)
      FileClose($file)
   EndIf
EndFunc

This could also be done using the 'start' parameter

Link to post
Share on other sites
47 minutes ago, levila said:

Let say logs appear "Markus" in line no 5, and next new event triggered and new "markus" string on different line.

not tested, if you meant checking log only for the latest line appended for 'markus', i would start looking from the bottom of the file up

tip for naming variable practice: $iLineCount - the 'i' is for interger; $sFileName - 's'=string, $hFileOpen - h=handle, a=array, c=control ect...

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <File.au3>

Global Const $sFileName_Log = @ScriptDir & '\log.txt'

;~ _CheckLog("Markus")

Func _CheckLogFile($sSearchTerm)
    If Not FileExists($sFileName_Log) Then
        ConsoleWrite('!>!'&@ScriptLineNumber&': File not found ['&$sFileName_Log&']'&@CRLF) ;Red/Brown
    Else
        Local $iLineCount = _FileCountLines($sFileName_Log)
        If Not $iLineCount Then
            ConsoleWrite('!>!'&@ScriptLineNumber&': File is empty ['&$iLineCount&']'&@CRLF) ;Red/Brown
        Else
            Local $hFileOpen = FileOpen($sFileName_Log, $FO_READ)
            If $hFileOpen = -1 Then
                MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file.")
                Return False
            EndIf

            ;read file from bottom up - assuming log file appending new line at the end of the file
            For $i = $iLineCount To 1 Step -1
                Local $sFileRead = FileReadLine($hFileOpen, $i)
                Local $iPosition  = StringInStr($sFileRead, $sSearchTerm)
                
                Local $sStr = @ScriptLineNumber&': line-'& $i &' | position-'& $iPosition &' | found-'& $sSearchTerm
                ConsoleWrite($iPosition > 0 ? '   '& $sStr &' &@CRLF : '!>!'& $sStr &' ' &@CRLF) ;White/Red
                
                ;If Not $iPosition Then
                    ;MsgBox(0,"Fails", "No ["& $sSearchTerm &"] Found", 5) ;<---warning endless MsgBox() popup
                ;Else
                    ;MsgBox(0,"Found", "["& $sSearchTerm &"] is located @"& $iPosition, 5) ;<---warning endless MsgBox() popup
                ;EndIf
            Next
            
            FileClose($hFileOpen)
        EndIf
    EndIf
EndFunc

 

Edited by zeenmakr
Link to post
Share on other sites
On 9/26/2020 at 4:42 PM, zeenmakr said:

not tested, if you meant checking log only for the latest line appended for 'markus', i would start looking from the bottom of the file up

tip for naming variable practice: $iLineCount - the 'i' is for interger; $sFileName - 's'=string, $hFileOpen - h=handle, a=array, c=control ect...

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <File.au3>

Global Const $sFileName_Log = @ScriptDir & '\log.txt'

;~ _CheckLog("Markus")

Func _CheckLogFile($sSearchTerm)
    If Not FileExists($sFileName_Log) Then
        ConsoleWrite('!>!'&@ScriptLineNumber&': File not found ['&$sFileName_Log&']'&@CRLF) ;Red/Brown
    Else
        Local $iLineCount = _FileCountLines($sFileName_Log)
        If Not $iLineCount Then
            ConsoleWrite('!>!'&@ScriptLineNumber&': File is empty ['&$iLineCount&']'&@CRLF) ;Red/Brown
        Else
            Local $hFileOpen = FileOpen($sFileName_Log, $FO_READ)
            If $hFileOpen = -1 Then
                MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file.")
                Return False
            EndIf

            ;read file from bottom up - assuming log file appending new line at the end of the file
            For $i = $iLineCount To 1 Step -1
                Local $sFileRead = FileReadLine($hFileOpen, $i)
                Local $iPosition  = StringInStr($sFileRead, $sSearchTerm)
                
                Local $sStr = @ScriptLineNumber&': line-'& $i &' | position-'& $iPosition &' | found-'& $sSearchTerm
                ConsoleWrite($iPosition > 0 ? '   '& $sStr &' &@CRLF : '!>!'& $sStr &' ' &@CRLF) ;White/Red
                
                ;If Not $iPosition Then
                    ;MsgBox(0,"Fails", "No ["& $sSearchTerm &"] Found", 5) ;<---warning endless MsgBox() popup
                ;Else
                    ;MsgBox(0,"Found", "["& $sSearchTerm &"] is located @"& $iPosition, 5) ;<---warning endless MsgBox() popup
                ;EndIf
            Next
            
            FileClose($hFileOpen)
        EndIf
    EndIf
EndFunc

 

For this method it will only execute for the latest line appended for String "markus", and keep looping the Alert/Msgbox until he find new line that have same String.

I want it to detect the 1st string and will go for another string if exist and ignore the 1st string.

And the logs are updated in every 5 min, and sometimes in 5 min there is 2 Logs appear with the same string that i want to be alert.

 

Link to post
Share on other sites
On 9/26/2020 at 4:28 PM, mikell said:

You might use in StringInStr the 'occurence' parameter and increment it
Something like this (untested)

func _CheckString()
    Local Static $occ = 1
    Consolewrite("Entering at the function at " & @HOUR & ":" & @MIN & @CRLF)
    
   If StringInStr($read, "Markus", 0, $occ) Then
      $position = StringInStr($read, "Markus", 0, $occ)
      $occ += 1
      MsgBox(0,"","Alert Found - Logs Line No "&$position, 5)
      FileClose($file)
   Else
      MsgBox(0,"","No Alert found", 5)
      FileClose($file)
   EndIf
EndFunc

This could also be done using the 'start' parameter

Thx for this, i did test this script, but it keep looping after all string check. so i did some changes and it work like charm.

func _CheckString()
   $file = FileOpen("c:\hello.log", 0)
   $read = FileRead($file)
   Local Static $occ = 1
   $position = StringInStr($read, "logged in", 0, $occ)

   If $position > 0 Then
      $occ += 1
      MsgBox(0,"","Alert Found - Logs Line No "&$position)
   Else
      MsgBox(0,"","No Alert found")
   EndIf
   FileClose($file)
EndFunc

It will detect the String and will ignore it until new string appear in new line.

Wink2 😍, thx all for the help. but if u think there is still error in my script would love if u correct me.

Link to post
Share on other sites
4 hours ago, levila said:

And the logs are updated in every 5 min, and sometimes in 5 min there is 2 Logs appear with the same string that i want to be alert.

this update only check for changes made to log file recently -within the last 5mins- and report all instances found. 

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <File.au3>
#include <Array.au3>

Global Const $_FILEPATH_LOG = @ScriptDir & '\_CheckLogFile.txt'
Global Const $_FILEPATH_INI = @ScriptDir & '\_CheckLogFile.ini'
Global $_LAST_LOG_LINE_POSITION = IniRead($_FILEPATH_INI,"Options","Last checked position", 0)

;for testing purposes
FileWrite($_FILEPATH_LOG, 'Markus is late again'&@CRLF&'Today is a fine day'&@CRLF&'And where is Markus'&@CRLF)

_CheckLogFile("Markus")

Func _CheckLogFile($sSearchTerm)
    Local $sFileRead
    Local $iPosition
    Local $aResults[0]
    Local $iTotalFound = 0
            
    If Not FileExists($_FILEPATH_LOG) Then
        ConsoleWrite('!>!'&@ScriptLineNumber&': File not found ['&$_FILEPATH_LOG&']'&@CRLF) ;Red/Brown
    Else
        Local $iLineCount = _FileCountLines($_FILEPATH_LOG)
        If Not $iLineCount Or $iLineCount = $_LAST_LOG_LINE_POSITION Then
            Local $sStr = @ScriptLineNumber&': '
            ConsoleWrite($iLineCount > 0 ?  '>-> '& $sStr &'NO NEW LOG UPDATED - ['&$_FILEPATH_LOG&']' &@CRLF : '' & _ ;Yellow
                                            '!>! '& $sStr &'Log File is Emptied - ['&$_FILEPATH_LOG&']'&@CRLF) ;Red
        Else
            ; making sure log file new or got reset
            If $iLineCount < $_LAST_LOG_LINE_POSITION Then
              $_LAST_LOG_LINE_POSITION = 0
              IniWrite($_FILEPATH_INI, "Options", "Last checked position", 0)
            EndIf
            
            Local $hFileOpen = FileOpen($_FILEPATH_LOG, $FO_READ)
            If $hFileOpen = -1 Then
                MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file.")
                Return False
            EndIf

            ; only check from: previous line position + 1 to: end of file
            Local $iReposition = $_LAST_LOG_LINE_POSITION + 1 ;<--- prevent from re-checking the last known line position
            For $i = $iReposition To $iLineCount
;~             For $i = $iLineCount To 1 Step -1
                $sFileRead = FileReadLine($hFileOpen, $i)
                $iPosition  = StringInStr($sFileRead, $sSearchTerm)
                ;debug
                Local $sStr = @ScriptLineNumber&': line-'& $i &' | position-'& $iPosition &' | '
                ConsoleWrite($iPosition > 0 ? '    '& $sStr &'found-'& $sSearchTerm &@CRLF : '!>! '& $sStr &'NOT FOUND'&@CRLF) ;White/Red
                ;--opt 1---
                ;keep track all
;~                 $iTotalFound += 1
;~                 _ArrayAdd($aResults,    '#'& $iTotalFound &' - line: '    & $i &'/'& $iLineCount & _
;~                                         ' pos: '     & $iPosition & _
;~                                         ' str: '     & $sSearchTerm)
                ;--opt 2---
                ;keep track only found
                If Not $iPosition Then ContinueLoop
                $iTotalFound += 1
                _ArrayAdd($aResults,    '#'& $iTotalFound &' - line: '    & $i &'/'& $iLineCount & _
                                        ' pos: '     & $iPosition & _
                                        ' str: '     & $sSearchTerm)
            Next
                
            ; remember and prevent from reading old log lines in case of system crash/shutdown/or script terminated
            If $iLineCount > $_LAST_LOG_LINE_POSITION Then
              $_LAST_LOG_LINE_POSITION = $iLineCount
              IniWrite($_FILEPATH_INI, "Options", "Last checked position", $_LAST_LOG_LINE_POSITION)
            EndIf
            FileClose($hFileOpen)
            
            _ArrayInsert($aResults, 0, $iTotalFound)
            If UBound($aResults)-1 Then
                ;MsgBox(0,"Found", $iTotalFound &" ["& $sSearchTerm &"] found", 5)
                _ArrayDisplay($aResults, @ScriptLineNumber&' | Found '&$iTotalFound)
            Else
                MsgBox($MB_ICONWARNING,"Not Found", $iTotalFound &" ["& $sSearchTerm &"] found", 5)
                
            EndIf
        EndIf
    EndIf
EndFunc

 

Link to post
Share on other sites
  • 3 weeks later...
  • 4 weeks later...
On 10/13/2020 at 10:15 PM, levila said:

Guys, how can i check for multiple strings,

Let say i wan it trigger if Markus, Ben, Tammy string exist.

 

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <File.au3>
#include <Array.au3>

Global Const $_FILEPATH_LOG = @ScriptDir & '\_CheckLogFile.txt'
Global Const $_FILEPATH_INI = @ScriptDir & '\_CheckLogFile.ini'
Global $_LAST_LOG_LINE_POSITION = IniRead($_FILEPATH_INI,"Options","Last checked position", 0)

;for testing purposes
FileWrite($_FILEPATH_LOG, 'Markus and Ben are late again'&@CRLF&'Today is a fine day'&@CRLF&'And where are Markus, Ben and Tammy'&@CRLF)

_CheckLogFile("Markus|Ben|Tammy")

Func _CheckLogFile($sSearchTerms)
    Local $sFileRead
    Local $iPosition
    Local $aResults[0]
    Local $iTotalFound = 0
    Local $aSearchTerms = StringSplit($sSearchTerms, '|', 2)
            
    If Not FileExists($_FILEPATH_LOG) Then
        ConsoleWrite('!>!'&@ScriptLineNumber&': File not found ['&$_FILEPATH_LOG&']'&@CRLF) ;Red/Brown
    Else
        Local $iLineCount = _FileCountLines($_FILEPATH_LOG)
        If Not $iLineCount Or $iLineCount = $_LAST_LOG_LINE_POSITION Then
            Local $sStr = @ScriptLineNumber&': '
            ConsoleWrite($iLineCount > 0 ?  '>-> '& $sStr &'NO NEW LOG UPDATED - ['&$_FILEPATH_LOG&']' &@CRLF : '' & _ ;Yellow
                                            '!>! '& $sStr &'Log File is Emptied - ['&$_FILEPATH_LOG&']'&@CRLF) ;Red
        Else
            ; making sure log file new or got reset
            If $iLineCount < $_LAST_LOG_LINE_POSITION Then
              $_LAST_LOG_LINE_POSITION = 0
              IniWrite($_FILEPATH_INI, "Options", "Last checked position", 0)
            EndIf
            
            Local $hFileOpen = FileOpen($_FILEPATH_LOG, $FO_READ)
            If $hFileOpen = -1 Then
                MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file.")
                Return False
            EndIf

            ; only check from: previous line position + 1 to: end of file
            Local $iReposition = $_LAST_LOG_LINE_POSITION + 1 ;<--- prevent from re-checking the last known line position
            For $i = $iReposition To $iLineCount
;~             For $i = $iLineCount To 1 Step -1
                $sFileRead = FileReadLine($hFileOpen, $i)
;~                 $iPosition  = StringInStr($sFileRead, $sSearchTerms)
                
                Local $iPosition = False
                Local $jPosition = 0
                Local $sPosition = ''
                Local $sSearchTerms_result = ''
;~                 _ArrayDisplay($aSearchTerms, UBound($aSearchTerms))
                For $j = 0 To UBound($aSearchTerms)-1
                    $jPosition  = StringInStr($sFileRead, $aSearchTerms[$j])
                    If $jPosition Then 
                        $iPosition = True
                        $sPosition  = $sPosition &','& $jPosition
                        $sSearchTerms_result = $sSearchTerms_result&','&$aSearchTerms[$j]
                        ConsoleWrite('>->'&@ScriptLineNumber&': Line# '&$i&' | Item# '&$j&' - '&$jPosition&'='&$aSearchTerms[$j]&@CRLF) ;Blue/Cyan
                    EndIf
                Next
                If $iPosition Then
                    $sPosition = StringTrimLeft($sPosition, 1)
                    $sSearchTerms_result = StringTrimLeft($sSearchTerms_result, 1)
                EndIf
                    
                
                ;debug
                Local $sStr = @ScriptLineNumber&': line-'& $i &' | position-('& $sPosition &') | '
                ConsoleWrite($iPosition > 0 ? '    '& $sStr &'found-('& $sSearchTerms_result &')'&@CRLF : '!>! '& $sStr &'NOT FOUND for neither [' &$sSearchTerms&']'&@CRLF) ;White/Red
                ;--opt 1---
                ;keep track all
;~                 $iTotalFound += 1
;~                 _ArrayAdd($aResults,    '#'& $iTotalFound &' - line: '    & $i &'/'& $iLineCount & _
;~                                         ' pos: '     & $sPosition & _
;~                                         ' str: '     & $sSearchTerms)
                ;--opt 2---
                ;keep track only found
                If Not $iPosition Then ContinueLoop
                $iTotalFound += 1
                _ArrayAdd($aResults,    'result #'& $iTotalFound &')|'&@CRLF& _
                                        '   log_line: ('    & $i &'/'& $iLineCount &')|'& _
                                        '   at_pos: ('     & $sPosition &')|'& _
                                        '   matched: ('     & $sSearchTerms_result &')')
            Next
                
            ; remember and prevent from reading old log lines in case of system crash/shutdown/or script terminated
            If $iLineCount > $_LAST_LOG_LINE_POSITION Then
              $_LAST_LOG_LINE_POSITION = $iLineCount
              IniWrite($_FILEPATH_INI, "Options", "Last checked position", $_LAST_LOG_LINE_POSITION)
            EndIf
            FileClose($hFileOpen)
            
            _ArrayInsert($aResults, 0, $iTotalFound)
            If UBound($aResults)-1 Then
                ;MsgBox(0,"Found", $iTotalFound &" ["& $sSearchTerms &"] found", 5)
                _ArrayDisplay($aResults, @ScriptLineNumber&' | Found '&$iTotalFound)
            Else
                MsgBox($MB_ICONWARNING,"Not Found", $iTotalFound &" ["& $sSearchTerms &"] found", 5)
                
            EndIf
        EndIf
    EndIf
EndFunc

 

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By OneSolution
      Hi guys! I have these checkbox that I'm trying to click on. They have the same inner-text string but a different ID. Sometime there can be as many as 4 checkbox
      with the same string but the ID is always different. I tried a few methods down below but I'm unable to make any real results. Any suggestions or solutions I would
      appreciate it very much.
      <ul><li class="cx-list-item-wrapper" data-day="Aug 2 2018 07:27:37 GMT-0700 (Pacific Daylight Time)"><div class=""><div class="cx-list-item-container"><div class="cx-list-item cx-item-icon-2 pointer-cursor"><div class="cx-item-contents cx-item-time col-md-2"><!-- react-text: 675 -->Morning<!-- /react-text --><!-- react-text: 676 -->&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-1"><!-- react-text: 678 -->OTHER<!-- /react-text --><!-- react-text: 679 -- >&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-2"><!-- react-text: 681 -->8:30 AM<!-- /react-text --><!-- react-text: 682 -->&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-2"><!-- react-text: 684 -->10:30 AM<!-- /react-text --><!-- react-text: 685 -->&nbsp;<!-- /react-text -- ></div><div class="cx-item-contents col-md-1"><!-- react-text: 687 -->SRV<!-- /react-text --><!-- react-text: 688 -->&nbsp;<!-- /react-text --></div></div></div><div class="pull-right cx-listitem-chk"><div><input id="cx_checkbox1" class="cx-fa-chk cx-selfschedule-chk" value="on" type="checkbox"><label for="cx_checkbox1"></label></div></div></div></li><li class="cx-list-item-wrapper" data-day="Aug 2 2018 07:27:37 GMT-0700 (Pacific Daylight Time)"><div class=""><div class="cx-list-item-container"><div class="cx-list-item cx-item-icon-2 pointer-cursor"><div class="cx-item-contents cx-item-time col-md-1"><!-- react-text: 698 -- >Morning<!-- /react-text --><!-- react-text: 699 -->&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-1"><!-- react-text: 701 -->OTHER<!-- /react- text --><!-- react-text: 702 -->&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-2"><!-- react-text: 704 -->8:30 AM<!-- /react-text --><!-- react-text: 705 -->&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-2"><!-- react-text: 707 -->2:30 PM<!-- /react-text --><!-- react-text: 708 -- >&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-1"><!-- react-text: 710 -->SRV<!-- /react-text --><!-- react-text: 711 -->&nbsp;<!-- /react-text --></div></div></div><div class="pull-right cx-listitem-chk"><div><input id="cx_checkbox2" class="cx-fa-chk cx-selfschedule-chk" value="on" type="checkbox"><label for="cx_checkbox2"></label></div></div></div></li></ul> I tried the _IETagNameGetCollection() but it only check the box but doesn't fire the event! And I'm unable to submit that without a click action.
      Func _Box1() $oInputs = _IETagNameGetCollection($oIE, "input") For $oInput In $oInputs If $oInput.id == "cx_checkbox1" Then $oInput.checked = true Next Sleep(10) ToolTip('box1') EndFunc ;==>_Box1 I also tried click by text.The boxes do get check by a click but the problem with that is it will select every box that has the same string. I'm allowed only to check 1 box selection at a time per day for the submit button to work.  Any preference to select only the second box and bypass the other?
      Func _Morning() For $a In _IETagNameGetCollection($oIE, "div") If StringInStr(_IEPropertyGet($a, "innerText"), "Morning") Then _IEAction($a, "click") EndIf Next Sleep(10) ToolTip('Morning selected') EndFunc ;==>Morning The last method I tried was _IEGetObjById(). It doesn't click or respond to the checkbox.
      Func _Click1() $oChk = _IEGetObjById($oIE, "cx_checkbox1") _IEAction($oChk, 'click') Sleep(20) ToolTip('box1') EndFunc ;==>_Click1  
    • By DynamicRookie
      Hey there!
       
      I've been developing a artificial intelligence.

      My first hard task was letting the A.I know when a sentence is found in memory with different words
      What i tried to do here is simply, get all the words in user sentence that could be used
      as a identifier
              
              example: Steve Jobs
              
              then identify the sentence purpose with the words we found in the past "for" loop
              
              example: Do/Know/You/Who/Steve/Jobs
              
              Compare the example in the following matching sentences in memory.
              
              1-Steve jobs was a known person
              2-Do you know who barack obama is?
              3-Do you know Steve jobs?
              4-Do you know who steve jobs is?
              5-How much money steve jobs had
              
              Then find the sentence that has way more matches than the other ones, remember that if the identifier words were not found
              (Steve jobs) then the sentence is invalid.
              
              Every sentence has a different answer and is important that the right one is chosen.
              
      If there's no more than the half of words in matches, then assign a variable the result of function, such as a return but for a global var.
      I couldn't figure out how to do that with StringRegExp.
       
      I honestly need help with detecting identifiers on memory sentences.
      I would also like to let the AI know typos, meaning that moeny and money means the same thing.
      Any help is hugely appreciated.

       
    • By LoneWolf_2106
      Hi everybody,
      i have a log file with several entries like the following one:
      INFO [26.04.2017 11:37:48] [main] XML-Data: <online-activation> <general> <userid>XYZ</userid> <mac-address/> <OU>VG-DE</OU> <ROLE>KDT</ROLE> <FOA>PRO;FC;DOM;MDD</FOA> <BRD>XYZ;IMP</BRD> </general> <applications> <app expiration-date="2017-10-01" name="BB-INFO"/> <app expiration-date="2017-10-01" name="MMSKD"/> <app expiration-date="2017-10-01" name="FM-TOOL"/> <app expiration-date="2017-04-05" name="WEB-BTD"/> <app expiration-date="2017-10-01" name="OFFLINE-BTD"/> <app expiration-date="2017-10-01" name="MDU-UPD"/> <app expiration-date="2017-10-01" name="MDU"/> <app expiration-date="2017-04-05" name="WEB-WDA"/> <app expiration-date="2017-04-05" name="WEB-ETD"/> <app expiration-date="2017-10-01" name="OFFLINE-WDA"/> <app expiration-date="2017-10-01" name="OFFLINE-ETD"/> </applications> </online-activation>  
      I need to collect all the XML-Data, my search doesn't work:
       
      Func FileSearch() $j=0 For $i = 0 To UBound($content_array) - 1 $search_result=StringInStr($content_array[$i],$search) If $search_result<>0 Then ReDim $searchResultArray[UBound($searchResultArray) + 1] $searchResultArray [$j] = $content_array[$i] _ArrayDisplay($searchResultArray) $j+=1 EndIf Next EndFunc If i search for "online-activation", it retrieves only the first and the last tag, but not what is within.
      In addition, when i use FileReadToArray, all the entries between <online-activation> and </online-activation>

    • By MrSparty1995
      I have a good handle on how to read a file line by line, and search for a given string.
      Basically using, FileOpen, FileReadLine, and StringInStr.
      I have been trying to figure out why my search keeps coming back with no match.
      For example, if my string line was "Where is Waldy", and I was searching for Waldy that comes back fine.
      But in my file, Let's say it is
      Where is "Waldy"
      So i read that line in and do a search for Waldy, but i comes back with no match since there is quotes around it.
      Is there a way to resolve this?
      Here is my actual example
      The line comes back like this
          <JposEntry logicalName="LineDisp_iSC480">
      I'm searching for LineDisp_iSC480, but its coming back with no match due to the quotes.
      Thanks in advance, James
    • By AliOzturk
      Hello, I want to be able to search for multiple strings and if any of the strings are found I want it returned which one it is. I've been able to search for multiple strings using the OR command, but I'm not sure how I am supposed to make it return which of my strings is found. I've given an example below
      If StringInStr($html, Batman) OR StringInStr($html, Superman) Then MsgBox(0, "Success", "The string found was: Superman") EndIf So it will search for the two strings and whichever it founds it will return me with. How can I make that work?
×
×
  • Create New...