the_lord_mephy Posted January 23, 2005 Posted January 23, 2005 What I want to do is to first get the amount of lines in a txt file using _FileCountLines. Then I want to create an array of the same amount of elements as the amount of lines in the txt file. Finally, I want to store each line with its place in the file corresponding with the subscript in which it is stored. My site for HTML Help :)[quote name='Valik' date='Oct 15 2004, 12:29 PM']Maybe nobody is an "elite uber-coder" like me because thinking is a capital offense in today's online-world?[right][snapback]36427[/snapback][/right][/quote]
Administrators Jon Posted January 23, 2005 Administrators Posted January 23, 2005 What I want to do is to first get the amount of lines in a txt file using _FileCountLines. Then I want to create an array of the same amount of elements as the amount of lines in the txt file. Finally, I want to store each line with its place in the file corresponding with the subscript in which it is stored.There's a standard include for this. This is what it looks like:;=============================================================================== ; ; Description: Reads the specified file into an array. ; Syntax: _FileReadToArray( $sFilePath, $aArray ) ; Parameter(s): $sFilePath - Path and filename of the file to be read ; $aArray - The array to store the contents of the file ; Requirement(s): None ; Return Value(s): On Success - Returns 1 ; On Failure - Returns 0 and sets @error = 1 ; Author(s): Jonathan Bennett <jon at hiddensoft com> ; Note(s): None ; ;=============================================================================== Func _FileReadToArray($sFilePath, ByRef $aArray) ;============================================== ; Local Constant/Variable Declaration Section ;============================================== Local $hFile $hFile = FileOpen($sFilePath, 0) If $hFile = -1 Then SetError(1) Return 0 EndIf $aArray = StringSplit( FileRead($hFile, FileGetSize($sFilePath)), @LF) FileClose($hFile) Return 1 EndFunc ;==>_FileReadToArray
the_lord_mephy Posted January 24, 2005 Author Posted January 24, 2005 Alright, that works, but now I want to split the text of each line with Delimeters of | and store the first side of the | in one array and the second side in another. My site for HTML Help :)[quote name='Valik' date='Oct 15 2004, 12:29 PM']Maybe nobody is an "elite uber-coder" like me because thinking is a capital offense in today's online-world?[right][snapback]36427[/snapback][/right][/quote]
scriptkitty Posted January 24, 2005 Posted January 24, 2005 It looks like you have only one delimiter per line. ok, lets say you have file A: bob|5 greg|6 sam|10 when you use that function it makes array x $x[] now you can make a different array from the first $count=ubound($x) Dim $y[$count][2] ; next set up a loop for $i=1 to $count $data=StringSplit($x[$i],"|") ; data becomes an array if $data[0]=2 then $y[$i][0]=$data[1] ;place first half in first part of array $y[$i][1]=$data[2] ;place second half in second part of array else msgbox(1,"Error","Bad data in file") endif next I left the actual programming up to you, but that is one way. AutoIt3, the MACGYVER Pocket Knife for computers.
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