/// <summary> /// Process a set of CSV lines /// </summary> /// <param name="lines"></param> private void ReadCsv(List <string> lines) { var separator = new char[] { ',' }; // First row is column headers string columnHeaderLine = lines[0]; string[] fileColHeaders = columnHeaderLine.Trim().Split(separator); _columnNames.Clear(); int columnPosition = 0; // Store the ordinal position of each column foreach (var columnHeader in fileColHeaders) { _columnNames.Add(columnHeader, columnPosition++); } // Extract all the data for (int lineIndex = 1 /* Skip first */; lineIndex < lines.Count; lineIndex++) { if (string.IsNullOrEmpty(lines[lineIndex])) { continue; } var values = new List <string>(lines[lineIndex].Trim().Split(separator)); CsvLine nextLine = new CsvLine(values); _rows.Add(nextLine); } }
/// <summary> /// Process a set of CSV lines /// </summary> /// <param name="lines"></param> private void ReadCsv(List<string> lines) { var separator = new char[] { ',' }; // First row is column headers string columnHeaderLine = lines[0]; string[] fileColHeaders = columnHeaderLine.Trim().Split(separator); _columnNames.Clear(); int columnPosition = 0; // Store the ordinal position of each column foreach (var columnHeader in fileColHeaders) { _columnNames.Add(columnHeader, columnPosition++); } // Extract all the data for (int lineIndex = 1 /* Skip first */; lineIndex < lines.Count; lineIndex++) { if (string.IsNullOrEmpty(lines[lineIndex])) { continue; } var values = new List<string>(lines[lineIndex].Trim().Split(separator)); CsvLine nextLine = new CsvLine(values); _rows.Add(nextLine); } }