Home AMX Technical Discussion

Are there any CSV parsers floating around on this forum?

travistravis Junior MemberPosts: 180
I wrote one a long time ago, but it kind of sucked.

You can't search the forum for "CSV". Searching for "parser", I didn't see anything.


  • PhreaKPhreaK Senior Member Posts: 966
    If you're just wanting to read the data into a two (well, technically 3) dimensional array what about iterating over each line with explode(..).
  • PsyenceFactPsyenceFact Junior Member Posts: 29
    You could use DuetParseCmdParam from SNAPI.axi to separate a CSV string into individual parameters. Something along the lines of:
    define_function integer ParseCSV(char cCSVString[], char cParameters[][])
    	stack_var integer nNumParameters  // number of parameters found in cCSVString
    	nNumParameters = 0
            while (length_array(cCSVString)) {
                cParameters[nParameters] = DuetParseCmdParam(cCSVString)
    	set_length_array(cParameters, nNumParameters)
    	return nNumParameters
    The total number of variables in the CSV line is returned from the function, and the individual variables are returned in whatever variable was passed as cParameters.

  • travistravis Junior Member Posts: 180

    I found some java article about CSV and converted it to netlinx. It's a mess. Seems to mostly work. I've lost interest.
  • DHawthorneDHawthorne Junior Member Posts: 4,584
    It seems to me that is would be as much work adapting a general parser to specific data as writing a new one each time. There is too much variance in how a CSV can store data. Just read it in, line-by-line, and break it into tokens at the commas. What you do with the tokens is the trick, and that is different for every data set.
Sign In or Register to comment.