Jump to content

trouble parsing data from an array


Recommended Posts

i am having an issue with an array. im not very versed in them but i have a bit of code that gets the output of a console app (ipconfig/all). it is loaded into an array but there is a lot of info i dont need. i need to find a way to separate each table into another array (or possibly another array dimension) to either edit individual elements or delete the table entirely. im really having a time with this project. arrays were never my strong point so any help is greatly appreciated.

#include <Constants.au3>
#include <file.au3>
#Include <string.au3>
#include <array.au3>
dim $array
Local $pid = Run("ipconfig /all", @SystemDir, @SW_HIDE, $STDOUT_CHILD)
ProcessWaitClose($pid)
$output=StdoutRead($pid)
ConsoleWrite($output)

;swapping these two changes the format but i dont know if thats the right direction
;~ $array=StringSplit($output, @CR,1)
$array=StringSplit($output, @CRLF&@CRLF,1)

$i=-1
$index=_ArraySearch($array, "Tunnel adapter","","","",1)
_ArrayDisplay($array)
Edited by bobbintb
Link to comment
Share on other sites

You can use _ArrayDelete($Array, Array number) to get rid of stuff that you don't need. Another thing you can do is something like this

$Text = ""
For $i = 1 To UBound($array) - 1
    If StringInStr($array[$i], "Tunnel adapter") Then $Text &= $array[$i] & "|"
Next

That'll get all the array values with "Tunnel adapter" in them, and put it into a string, seperated by "|"... You could also create another array and put them there, I don't know. You can do whatever you want. I don't quite get what you're asking. If you just want to isolate an array part to work with, from the array display menu, on the left pick the number of the stuff you want to use, and treat it as a normal string. $array[2] = "Host Name . . . . . . . . . . . . : SquirrleMSI

Primary Dns Suffix . . . . . . . :

Node Type . . . . . . . . . . . . : Broadcast

IP Routing Enabled. . . . . . . . : No

WINS Proxy Enabled. . . . . . . . : No

DNS Suffix Search List. . . . . . : hsd1.wa.comcast.net."

it might be hard to use that info because there are line breaks... that may be causing issues also. Try StringReplace($array[2], @CRLF, "###") or something. That puts out: " Host Name . . . . . . . . . . . . : SquirrleMSI### Primary Dns Suffix . . . . . . . : ### Node Type . . . . . . . . . . . . : Broadcast### IP Routing Enabled. . . . . . . . : No### WINS Proxy Enabled. . . . . . . . : No### DNS Suffix Search List. . . . . . : hsd1.wa.comcast.net."

Edited by mistersquirrle

We ought not to misbehave, but we should look as though we could.

Link to comment
Share on other sites

ok, so you're saying this whole thing:

Host Name . . . . . . . . . . . . : SquirrleMSI

Primary Dns Suffix . . . . . . . :

Node Type . . . . . . . . . . . . : Broadcast

IP Routing Enabled. . . . . . . . : No

WINS Proxy Enabled. . . . . . . . : No

DNS Suffix Search List. . . . . . : hsd1.wa.comcast.net.

into an array?

try $Array2 = StringSplit($Array[2], @CRLF, 1) and display that, see what you get

We ought not to misbehave, but we should look as though we could.

Link to comment
Share on other sites

ok i think i kinda got it. here is what i have so far:

#include <Constants.au3>
#include <file.au3>
#Include <string.au3>
#include <array.au3>

Local $pid = Run("ipconfig /all", @SystemDir, @SW_HIDE, $STDOUT_CHILD)
ProcessWaitClose($pid)
$output=StdoutRead($pid)
ConsoleWrite($output)

$output=StringReplace($output,":"&@CRLF&@CRLF,":"&@CRLF)
$array=StringSplit($output,@CRLF&@CRLF,1)
$array[1]=$array[1]&":  "&@CRLF&$array[2]
_ArrayDelete($array,2)

dim $adapter[$array[0]]
$i=0
for $i= 1 to $array[0]
    Do

        $adapter[$i]=_StringExplode($array[$i],@CRLF)
        $i=$i+1
    Until $i= $array[0]
Next
_ArrayDelete($adapter[1],0)
_ArrayDisplay($adapter[5])
msgbox(0, "",$adapter[7])

the thing is now it seems to be arrays within an array. when i set it to display $adapter is shows about 12 blank elements. but when i have it show say, $adapter[7] it shows the adapter in an array. but i cant figure out how to edit those elements. i dont think its a 2d array because $adapter[7][1] says it has the wrong dimensions.

Link to comment
Share on other sites

ok... so what you want to do is, take all the information inbetween the line breaks and put those into an array, or another array dimention? That might be kinda hard to do... the best way to do that would be to manually set up a script to create these arrays, or a way to record the data. I'm not sure of a way to do what you want.

We ought not to misbehave, but we should look as though we could.

Link to comment
Share on other sites

This example may help you along.

;
#include <Constants.au3>
#include <file.au3>
#include <string.au3>
#include <array.au3>

Local $pid = Run("ipconfig /all", @SystemDir, @SW_HIDE, $STDOUT_CHILD)
ProcessWaitClose($pid)
$output = StdoutRead($pid)
ConsoleWrite($output & @CRLF & "====================================================" & @CRLF)
$output = StringRegExpReplace($output, "(\v+)", @CRLF)
$output = StringRegExpReplace($output, "((\. )+:)", "=")
$output = StringStripWS($output, 3)
ConsoleWrite($output & @CRLF & "====================================================" & @CRLF)

$array = StringSplit($output, @CRLF, 1)

Dim $aResult[$array[0]][2]
For $x = 1 To $array[0]
    If StringInStr($array[$x], "=") <> 0 Then
        $aLine = StringRegExp($array[$x], "\h*(.*=\h*)(.*)\h*", 3)
        $aResult[$x - 1][0] = $aLine[0]
        $aResult[$x - 1][1] = $aLine[1]
    Else
        $aResult[$x - 1][0] = $array[$x]
    EndIf
Next
_ArrayDisplay($aResult)
;
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...