erik7426 Posted October 7, 2010 Share Posted October 7, 2010 I have used FileReadToArray in the past for one dimensional arrays, this time however the file contains multiple data elements. I need to be able to read a text file that contains 3 fields (PC name, IP Address, Port Number) into a multi-dimensional array. The file is currently tab delimited, but that could be changed if needed. Can anyone provide any guidance on the best way to accomplish this? Link to comment Share on other sites More sharing options...
enaiman Posted October 7, 2010 Share Posted October 7, 2010 - Declare the big array to hold your results - read text file using _FileReadToArray - split every element from your array using the delimiter of your choice and populate your "big" array elements Easy enough SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
trung0407 Posted October 8, 2010 Share Posted October 8, 2010 FileReadLine => to read each line Dim $data[] StringSplit, with tab as delimiter => return an array of data ($line) $data[0] = StringSplit... loop to read the next line Link to comment Share on other sites More sharing options...
Tlem Posted October 8, 2010 Share Posted October 8, 2010 you can find a function here : http://www.autoitscript.fr/forum/viewtopic.php?f=21&t=2741 It's on French forum, but the comments of the function are in English. Best Regards.Thierry Link to comment Share on other sites More sharing options...
Mison Posted October 8, 2010 Share Posted October 8, 2010 Hi Erik, You can use nested loop. #include <Array.au3> ; for _ArrayDisplay Local $array [3][3] ; Fixed size 2d array. Use ReDim to expand array. $data = FileRead("data.txt") $row = StringSplit($data,@CRLF,3) ; flag 1 + 2. For more information, refer to the help file. For $i = 0 To UBound($row)-1 $col = StringSplit($row[$i],",",2) For $j = 0 To UBound($col)-1 $array[$i][$j] = $col[$j] Next Next _ArrayDisplay($array) data.txt ==> x1,x2,x3 y1,y2,y3 z1,z2,z3 Hi ;) Link to comment Share on other sites More sharing options...
erik7426 Posted October 8, 2010 Author Share Posted October 8, 2010 Thanks for all the advice. I ended up piecing code together that I found from several examples. This is what I came up with... #include <file.au3> #include <array.au3> Dim $aRows If Not _FileReadToArray("TTYID.txt", $aRows) Then MsgBox(4096, "Error", " Error reading file to Array error:" & @error) Exit EndIf Global $myTTYID[$aRows[0]][3] For $r = 1 To $aRows[0] $aCols = StringSplit($aRows[$r], @TAB, 1) For $c = 1 To $aCols[0] $myTTYID[$r - 1][$c - 1] = $aCols[$c] Next Next _ArrayDisplay($myTTYID, "$myTTYID") I don't know if it was the best or the most simple way, but it works... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now