Jump to content

Searching for a String in an Array


Recommended Posts

Please help i'm pulling my hair out and I cant figure out where I'm going wrong

Ive created a text document using pslist.exe of applications running on an external server the txt file looks like this but with more lines I've called it Applications.txt

iexplore           3700   8  17  722  57148     0:32:16.796    13:18:06.398
ARK Server Manager  2496   8 213 26308 124464     0:02:34.781    13:11:25.971
cmd                3668   8   1   28   1556     0:00:00.000    12:59:06.325
conhost            3672   8   2   57    988     0:00:00.046    12:59:06.325
ShooterGameServer  2420   8  20  384 4176520     2:53:29.171    12:59:06.294
conhost             700   8   2   57   2324     0:00:00.031    12:59:03.841
ts3server_win64    4896   8  26  223   9116     0:00:10.421     0:12:02.678

I've added the contents of it to an array

Local $aArray = FileReadToArray ("Applications.txt")
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "", "There was an error reading the file. @error: " & @error) ; An error occurred reading the current script file.
    EndIf

I'm trying to search the array for the string ShooterGameServer but I always get a reply of -1

$Search = _ArraySearch($aArray,"ShooterGameServer")
MsgBox (0,"", $Search)

I've used _ArrayDisplay ($aArray)

So I can see the array is getting loaded and

ShooterGameServer  2420   8  20  384 4176520     2:53:29.171    12:59:06.294

is shown on row [49]

 

Regards Edd

 

Link to comment
Share on other sites

This will work:

#include <File.au3>
#include <Array.au3>

Local $aArray = FileReadToArray("Applications.txt")
If @error Then
    MsgBox($MB_SYSTEMMODAL, "", "There was an error reading the file. @error: " & @error) ; An error occurred reading the current script file.
Else
    ;_ArrayDisplay($aArray)
    $Search = _ArraySearch($aArray, "ShooterGameServer",0,0,0,1)
    ;ConsoleWrite($Search&@CRLF)
    MsgBox(0, "", $aArray[$Search] & 'found in row: ' & $Search)
EndIf

 

 

Edited by AutoBert
Link to comment
Share on other sites

  • Developers
1 hour ago, EddCase said:

ShooterGameServe

Hope you did read our forum rules with respect to game automation.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

why not just using this

https://www.autoitscript.com/autoit3/docs/functions/ProcessList.htm

 

should lead to this (not tested)

#include <MsgBoxConstants.au3>
Example()

Func Example()
    Local $aProcessList = ProcessList("ShooterGameServer")
    For $i = 1 To $aProcessList[0][0]
        MsgBox($MB_SYSTEMMODAL, "", $aProcessList[$i][0] & @CRLF & "PID: " & $aProcessList[$i][1])
    Next
EndFunc   ;==>Example

 

Edited by junkew
Link to comment
Share on other sites

or even exists instead of list

$sProc = "lsass.exe"
$sProcID = ProcessExists($sProc)

If $sProcID = 0 Then
    msgbox(0, '' , $sProc & " Does Not Exist")
Else
    msgbox(0, '' , $sProcID & ": " & $sProc)
EndIf

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

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