public RowCol getRowColCount(string lines) { RowCol res = new RowCol(); int cols = 0; foreach (var row in lines.Split(new string[] { Environment.NewLine }, StringSplitOptions.None)) { if (row != "\r") { res._row++; } var col = row.Trim().Split(' '); if (col == null && col.Count() == 0) { continue; } if (cols == 0) { cols = col.Count(); } else if (col.Count() != cols) { res._col = -1; return(res); } } res._col = cols; return(res); }
public string CheckMatch(RowCol arg1, RowCol arg2) { if (arg1._row != arg2._row) { return("Row count is not correct\nRow count should be " + arg2._row.ToString()); } if (arg1._col != arg2._col) { return("Column count is not correct\nColumn count should be " + arg2._col.ToString()); } return("Success"); }
public string Assign(string lines, int type) { string result = ""; RowCol v = getRowColCount(lines); if (v._col == -1) { return("Column is illegal, check again please"); } if (v._row == 0 || v._col == 0) { return("No data"); } RowCol v1 = new RowCol(); if (type == 0 || type == 2) { v1 = new RowCol() { _row = _np, _col = _m }; } else if (type == 1) { v1 = new RowCol { _row = _np, _col = _necessity }; } else if (type == 3 || type == 5) { v1 = new RowCol { _row = _np, _col = 1 }; } else if (type == 4) { v1 = new RowCol { _row = 2, _col = _np }; } else if (type == 6) { v1 = new RowCol { _row = _br, _col = _m }; } string msg = CheckMatch(v, v1); if (msg != "Success") { return(msg); } // Assign data if (!AssignData(lines, type)) { result = "Something went wrong while assign data"; } else { result = "Success"; } return(result); }