public static CsvData GetValidCsvData(string csvText, GlobalCCSettings gSettings) { var csvAsList = CsvParser.ReadAsList(csvText); CsvData csvData = new CsvData(); csvData.SetFromList(csvAsList); // END マーカーが有効な場合は END 以下を無視するようにする. if (gSettings.isEndMarkerEnabled) { int endMarkerIndex = gSettings.columnIndexOfEndMarker; string marker = gSettings.endMarker; if (endMarkerIndex < 0 || csvData.col <= endMarkerIndex) { throw new Exception("無効な columnIndexOfEndMarker です: " + endMarkerIndex); } for (int i = 0; i < csvData.row; i++) { if (csvData.Get(i, endMarkerIndex).Trim() == marker) { csvData = csvData.Slice(0, i); break; } } } // 無効な列を除外する csvData = csvData.SliceColumn(gSettings.columnIndexOfTableStart); return(csvData); }
public void Test_CsvDataSlice() { CsvData csvData = new CsvData(); csvData.SetFromList(new List <List <string> > { new List <string> { "00", "01", "02" }, new List <string> { "10", "11", "12" }, new List <string> { "20", "21", "22" }, }); var d0 = csvData.SliceColumn(0); Assert.AreEqual(3, d0.content.Length); Assert.AreEqual(3, d0.content[0].data.Length); var d1 = csvData.SliceColumn(1); Assert.AreEqual(3, d1.content.Length); Assert.AreEqual(2, d1.content[0].data.Length); Assert.AreEqual("01", d1.Get(0, 0)); var d2 = csvData.SliceColumn(0, -1); Assert.AreEqual(3, d2.content.Length); Assert.AreEqual(2, d2.content[0].data.Length); Assert.AreEqual("00", d2.Get(0, 0)); Assert.AreEqual("01", d2.Get(0, 1)); }