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

后端 未结 3 400
走了就别回头了
走了就别回头了 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:56

    As for parsing a CSV file, you are likely better off using a library (user-defined functions), especially if you e.g. have complex CSVs with quoted strings (commas inside of the "cell"/string) or line breaks, which are hard to handle.

    The best I can recommend is CSVSplit. Basically you have a function _CSVSplit that takes a whole CSV file (content, i.e. string!) and returns you a two-dimensional array:

    Local $sCSV = FileRead($sFilePath)
    If @error Then ; ....
    
    $aSplitArray = _CSVSplit($sCSV, ",")
    

    You can then do everything you want with this array. Obviously, CSVSplit also provides the "reverse" function for turning an array into a CSV string again, _ArrayToCSV.

提交回复
热议问题