-1

I'm trying to save the values โ€‹โ€‹of a specific column from a csv file. I want to take the largest number from this column and keep it in a variable. I'm trying this code, but the problem is that there is a comma in some fields and I can't get the correct values.

var columnQuery =  
        from line in strs  
        let elements = line.Split(',')  
        select Convert.ToInt32(elements[12]);  

var results = columnQuery.ToList();  

int max = results.Max();    
demo
  • 6,038
  • 19
  • 75
  • 149
Mark
  • 3
  • 3

1 Answers1

1

there is a comma in some fields

Then you obviously can't use a naive split like that. It's not hard to parse the line yourself, keeping track of quotes (which are required by the csv format for fields that contain commas), but it's much easier to just import a csv parser nuget and use that.

Blindy
  • 65,249
  • 10
  • 91
  • 131