Jump to content

Extract specific array rows... or something.


Recommended Posts

Hello All,

I have been a lurker for a good bit but have finally hit a stumbling block that I can't seem to overcome (even though it is undoubtedly super simple). I need some assistance if possible. 

Basically I have a giant list of names - 70k+ in a .txt document (but in the future probably coming from a direct STDOUT stream) I first StringSplit them and strip white space. Then I have a giant array that looks good on display. I do an _ArrayFindAll and it returns to me the element ID's instead of names... I need the names and can't figure out how to properly extract them. Ultimately the names will go in a list box that when selected will fill a field.

I know I am just being stupid. Any help you could offer would be greatly appreciated.

Here is a snippet of what I've got goin on. 

Case $ButtonSearch
            $ReadUsrInfoSearch = GUICtrlRead($F_GET_USRNME)
            $FileOpen = FileOpen("C:\name.txt")
            $FileRead = FileRead($FileOpen)
            FileClose($FileOpen)
            $aResult = StringSplit(StringStripWS($FileRead,4)," ")
            $blab = _ArrayFindAll($aResult, $ReadUsrInfoSearch, Default, Default, Default, 1, Default, False)
            _ArrayDisplay($blab)
            If @error Then
            MsgBox($MB_SYSTEMMODAL, "Not Found", ':' & $ReadUsrInfoSearch)

Thanks in advance!!!

 

 

Link to comment
Share on other sites

Roger that,

I have made an easier to read example for testing purposes. I also uploaded a text document with some test names. Thanks for the reply!! :)

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

$ReadUsrInfoSearch = "John"
$FileOpen = FileOpen("C:\UserList.txt")
$FileRead = FileRead($FileOpen)
FileClose($FileOpen)
$aResult = StringSplit(StringStripWS($FileRead,4)," ")
_ArrayDisplay($aResult)
$blab = _ArrayFindAll($aResult, "Ra", Default, Default, Default, 1, Default, False)
_ArrayDisplay($blab)

 

UserList.txt

Link to comment
Share on other sites

When you split text using StringSplit("Source String", "What To Find") - it gives you the number of items found in index 0.  If you expect to find a name in index 0, you should use StringSplit("Source String", "What To Find", 2).

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

$ReadUsrInfoSearch = "John"
$FileOpen = FileOpen("C:\UserList.txt")
$FileRead = FileRead($FileOpen)
FileClose($FileOpen)
$aResult = StringSplit(StringStripWS($FileRead,4)," ", 2) ; < ---- Add 2 here
_ArrayDisplay($aResult)
$blab = _ArrayFindAll($aResult, "Ra", Default, Default, Default, 1, Default, False)
_ArrayDisplay($blab)

 OR

 

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

$ReadUsrInfoSearch = "John"
$FileOpen = FileOpen("C:\UserList.txt")
$FileRead = FileRead($FileOpen)
FileClose($FileOpen)
$aResult = StringSplit(StringStripWS($FileRead,4)," ")
_ArrayDisplay($aResult)
$blab = _ArrayFindAll($aResult, "Ra", 1, Default, Default, 1, Default, False) ; < ---- Change first "Default" to 1 here
_ArrayDisplay($blab)

 

Also, are you aware that your name strings contain both spaces and tabs between the names?  Because that's going to make your results a little odd, seeing as you only strip multiple spaces.  You don't touch tabs at all.

How's my riding? Dial 1-800-Wait-There

Trying to use a computer with McAfee installed is like trying to read a book at a rock concert.

Link to comment
Share on other sites

There is another possible approach
If you split using a space as delimiter, that means that there is no space in the names to list, there are only letters ...
So you can use a regular expression and search for sequences of 'word' chars

#include <Array.au3>

$FileRead = FileRead("UserList.txt")
$aResult = StringRegExp($FileRead,'\w+', 3)
_ArrayDisplay($aResult)

$var = "Ra"
$res = StringRegExp($FileRead,'(?i)\w*' & $var & '\w*', 3)  ; (?i) = case insensitive
_ArrayDisplay($res)

 

Edited by mikell
Link to comment
Share on other sites

43 minutes ago, mikell said:

There is another possible approach
If you split using a space as delimiter, that means that there is no space in the names to list, there are only letters ...
So you can use a regular expression and search for sequences of 'word' chars

#include <Array.au3>

$FileRead = FileRead("UserList.txt")
$aResult = StringRegExp($FileRead,'\w+', 3)
_ArrayDisplay($aResult)

$var = "Ra"
$res = StringRegExp($FileRead,'(?i)\w*' & $var & '\w*', 3)  ; (?i) = case insensitive
_ArrayDisplay($res)

 

Bingo! This solution works magically...now I just have to think about it for a few hours to understand it. :) 

Thanks you both, very good answers!

Cheers!

Link to comment
Share on other sites

and with the arrayfind functions while we are skinning

#include <File.au3>

local $a
local $aOut[0]
$sSearch = "ra"

_FileReadToArray("UserList.txt" , $a , 0 , @TAB)

_ArrayDisplay($a)

For $i = 0 to ubound($a , 2) - 1
    $aMatch = _ArrayFindAll($a , $sSearch , 0 ,0 ,0 ,1 , $i)

    for $k = 0 to ubound($aMatch) - 1
        $aMatch[$k] = $a[$aMatch[$k]][$i]
    Next

    _ArrayConcatenate($aOut , $aMatch)
next



_ArrayDisplay($aOut)

 

Edited by iamtheky

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

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