public TabulateData GetSubColumns(IEnumerable <int> columnIndices) { if (columnIndices == null) { throw new ArgumentNullException(); } if (columnIndices.Count() == 0) { // we can't return a sub tabulate result with no column. return(null); } if (columnIndices.Any(i => i < 0 || i >= _columns.Length)) { throw new ArgumentException("column index is out of range"); } var columns = columnIndices.Select(i => _columns[i]); TabulateData subResult = new TabulateData(columns); foreach (var row in _rows) { var subRow = columnIndices.Select(i => row[i]); subResult.AddRow(subRow); } return(subResult); }
public static bool TryParse(string s, out TabulateData result) { if (string.IsNullOrEmpty(s)) { throw new ArgumentNullException(); } // split rows firstly. string[] rows = s.Split('\n'); // row[0] is the header string[] columns = rows[0].Split('\t'); result = new TabulateData(columns); for (int i = 1; i < rows.Length; ++i) { string[] values = rows[i].Split('\t'); if (!result.AddRow(values)) { return(false); } } return(true); }
public TabulateData GetSubColumns(IEnumerable <string> columns) { if (columns == null) { throw new ArgumentNullException(); } if (columns.Count() == 0) { // we can't return a sub tabulate result with no column. return(null); } var columnIndices = columns.Select(c => GetColumnIndex(c)); TabulateData subResult = new TabulateData(columns); foreach (var row in _rows) { var subRow = columnIndices.Select(i => i < 0 ? string.Empty : row[i]); subResult.AddRow(subRow); } return(subResult); }
public TabulateData GetSubRows(IEnumerable <int> rowIndices) { if (rowIndices == null) { throw new ArgumentNullException(); } var validRowIndices = rowIndices.Where(i => i >= 0 && i < RowCount); // even if there is no valid row index, we still need to return a sub tabulate result // with no row. TabulateData subResult = new TabulateData(_columns); foreach (var index in validRowIndices) { subResult.AddRow(_rows[index]); } return(subResult); }