Parse all the rows of a CSV file in a loop using AutoIt

后端 未结 3 394
走了就别回头了
走了就别回头了 2021-01-29 06:37

I have the following code to read a .csv file that contains two rows of data. I do not know what is wrong with it. How can I improve it to read a .csv file with two rows of data

3条回答
  •  隐瞒了意图╮
    2021-01-29 06:52

    Here is a program that will read a CSV file with 2 rows and output both data fields. If you have more rows change the input array to be larger.

    #include 
    #include 
    
    $file = FileOpen("test.csv", 0)
    
    If $file = -1 Then
       MsgBox(0, "error", "File doesn't exist or can't be read")
       Exit
    EndIf
    
       ; Read in lines of text until the EOF is reached
    While 1
        Local $line = FileReadLine($file)
        If @error = -1 Then ExitLoop
       $input = StringSplit($line, ",")
    
       ;This is reading fields 1 and 2. 
       ;The array index [0] 
       ;it will tell you how big the array is.
       Local $value1 = $input[1]
       Local $value2 = $input[2]
       ConsoleWrite("var=" & $value1)
       ConsoleWrite("var=" & $value2)
    
    WEnd
    

提交回复
热议问题