public static List<List<string>> ReadCsv(string path, Encoding encoding) { List<List<string>> rows = new List<List<string>>(); foreach (string line in File.ReadAllLines(path, encoding)) { rows.Add(CsvLineParserImpl.UnescapeLineToFieldList(line, ',')); } return rows; }
public static List <List <string> > Load(string path, Encoding encoding) { StringBuilder sbLog = new StringBuilder(); List <List <string> > rows = new List <List <string> >(); foreach (string line in File.ReadAllLines(path, encoding)) { rows.Add(CsvLineParserImpl.UnescapeLineToFieldList(line, ',')); } // 最初の2行は削除。 rows.RemoveRange(0, 2); // 各行の先頭3列は削除。 foreach (List <string> row in rows) { row.RemoveRange(0, 3); } //------------------------------ // データ部だけが残っています。 //------------------------------ // コメント行、データ行が交互に出てきます。 // コメント行を削除します。 List <List <string> > rows2; { rows2 = new List <List <string> >(); int rowCount1 = 0; foreach (List <string> row in rows) { // 奇数行がデータです。 if (rowCount1 % 2 == 1) { rows2.Add(row); } rowCount1++; } } #if DEBUG // デバッグ出力 { StringBuilder sb = new StringBuilder(); foreach (List <string> row2 in rows2) { foreach (string field in row2) { sb.Append(field); sb.Append(","); } sb.AppendLine(); } string filepath_HaiyakuLoad1 = EngineConf.GetResourceFullPath("OutputSyuruiToHaiyaku01DataRowOnly"); File.WriteAllText(filepath_HaiyakuLoad1, sb.ToString()); } #endif Data_KomahaiyakuTransition.map = new Dictionary <PieceType, Komahaiyaku185[]>(); int rowCount2 = 0; Komahaiyaku185[] table81 = null; foreach (List <string> row2 in rows2) { if (rowCount2 % 9 == 0) { table81 = new Komahaiyaku185[81]; int syuruiNumber = rowCount2 / 9 + 1; if (15 <= syuruiNumber) { goto gt_EndMethod; } Data_KomahaiyakuTransition.map.Add(Array_Komasyurui.Items_AllElements[syuruiNumber], table81); } //---------- // テーブル作り //---------- int columnCount = 0; foreach (string column in row2) { // 空っぽの列は無視します。 if ("" == column) { goto gt_NextColumn; } // 空っぽでない列の値を覚えます。 // 数値型のはずです。 int cellValue; if (!int.TryParse(column, out cellValue)) { throw new Exception($@"エラー。 path=[{path}] 「配役転換表」に、int型数値でないものが指定されていました。 rowCount=[{rowCount2}] columnCount=[{columnCount}"); } int masuHandle = (8 - columnCount) * 9 + (rowCount2 % 9);//0~80 sbLog.AppendLine($"({rowCount2},{columnCount})[{masuHandle}]{cellValue}"); table81[masuHandle] = Array_Komahaiyaku185.Items[cellValue]; gt_NextColumn: columnCount++; } rowCount2++; } gt_EndMethod: #if DEBUG { string filepath_HaiyakuLoad2 = EngineConf.GetResourceFullPath("OutputSyuruiToHaiyaku02Load"); File.WriteAllText(filepath_HaiyakuLoad2, sbLog.ToString()); } #endif return(rows); }