public void ParseTest() { const string quot = "\""; const string quot2 = quot + quot; const string ret = "\r\n"; const string sep = ";"; const string sep2 = ","; string[] data = { "columnA" + sep, "columnB" + sep2, "columnC" + sep, "columnD" + sep2, "columnE" + ret, " リンゴ " + sep2, "" + sep, (quot2 + "み" + quot2 + "かん").Enclose(quot) + sep2, ("バナ" + ret + "ナ").Enclose(quot) + sep, " パイナップル " + sep + ret, "" + sep, "" + sep2, "" + sep2, "" + sep, "" + ret, " ABCD ".Enclose(quot) + sep, ("E" + sep + "FG").Enclose(quot) + sep2, ("HIJ" + ret + "K" + ret + ret + "LMN").Enclose(quot) + sep, "OPQR"+sep2, "" }; var testData = data.ConcatWith(""); Console.WriteLine(testData); Console.WriteLine(""); using (var reader = new System.IO.StringReader(testData)) { var target = new XsvData<XsvDataRow>(new[] { sep, sep2 }); target.Read(reader); foreach (var row in target.Rows) { Console.WriteLine(row.ToString() + " <<"); } Console.WriteLine(""); foreach (var row in target.Rows) { Console.WriteLine(row.OutputFields(new[] { ":" }, ":") + " <<"); } var sb = new StringBuilder(); using (var writer = new StringWriter(sb)) { target.Write(writer); } Console.WriteLine("----------"); Console.WriteLine(sb.ToString()); } }
public void EditColumnHeaderTest() { string expected = "品番,名前,本体価格,メーカー,品名" + Environment.NewLine + "110,戦艦 比叡 ひえい,\"2,500\",H,比叡 ひえい" + Environment.NewLine + "119,航空戦艦 伊勢 いせ,\"3,200\",H,伊勢 いせ" + Environment.NewLine + "216,航空母艦 瑞鳳 ずいほう,\"2,000\",H,瑞鳳 ずいほう" + Environment.NewLine + "320,軽巡洋艦 名取 なとり,\"1,300\",T,名取 なとり" + Environment.NewLine + "334,重巡洋艦 那智 なち,\"1,800\",H,那智 なち" + Environment.NewLine + "xxx,不明 名無し,xxx,xxx," + Environment.NewLine; var target = new XsvData <ShipModelDataRow>(new[] { "," }); using (var reader = new System.IO.StringReader(data2)) { target.Read(reader); } target.AddColumnHeader("名前"); foreach (var row in target.Rows) { row["名前"] = new XsvField(row.船種 + " " + row.品名); } target.RemoveColumnHeader("税込価格"); target.RemoveColumnHeader("船種"); target.SwapColumnHeader("品名", "名前"); var sb = new StringBuilder(); using (var writer = new StringWriter(sb)) { target.Write(writer, ",", new XsvWriteSettings() { OutputsHeader = true, SynchronisesColumn = true, UpdatesField = false }); } Console.Write(sb.ToString()); Assert.AreEqual(expected, sb.ToString()); }
public void EditColumnHeaderTest() { string expected = "品番,名前,本体価格,メーカー,品名" + Environment.NewLine + "110,戦艦 比叡 ひえい,\"2,500\",H,比叡 ひえい" + Environment.NewLine + "119,航空戦艦 伊勢 いせ,\"3,200\",H,伊勢 いせ" + Environment.NewLine + "216,航空母艦 瑞鳳 ずいほう,\"2,000\",H,瑞鳳 ずいほう" + Environment.NewLine + "320,軽巡洋艦 名取 なとり,\"1,300\",T,名取 なとり" + Environment.NewLine + "334,重巡洋艦 那智 なち,\"1,800\",H,那智 なち" + Environment.NewLine + "xxx,不明 名無し,xxx,xxx," + Environment.NewLine; var target = new XsvData<ShipModelDataRow>(new[] { "," }); using (var reader = new System.IO.StringReader(data2)) { target.Read(reader); } target.AddColumnHeader("名前"); foreach (var row in target.Rows) { row["名前"] = new XsvField(row.船種 + " " + row.品名); } target.RemoveColumnHeader("税込価格"); target.RemoveColumnHeader("船種"); target.SwapColumnHeader("品名", "名前"); var sb = new StringBuilder(); using (var writer = new StringWriter(sb)) { target.Write(writer, ",", new XsvWriteSettings() { OutputsHeader = true, SynchronisesColumn = true, UpdatesField = false }); } Console.Write(sb.ToString()); Assert.AreEqual(expected, sb.ToString()); }
public void ParseTest() { const string quot = "\""; const string quot2 = quot + quot; const string ret = "\r\n"; const string sep = ";"; const string sep2 = ","; string[] data = { "columnA" + sep, "columnB" + sep2, "columnC" + sep, "columnD" + sep2, "columnE" + ret, " リンゴ " + sep2, "" + sep, (quot2 + "み" + quot2 + "かん").Enclose(quot) + sep2, ("バナ" + ret + "ナ").Enclose(quot) + sep, " パイナップル " + sep + ret, "" + sep, "" + sep2, "" + sep2, "" + sep, "" + ret, " ABCD ".Enclose(quot) + sep, ("E" + sep + "FG").Enclose(quot) + sep2, ("HIJ" + ret + "K" + ret + ret + "LMN").Enclose(quot) + sep, "OPQR" + sep2, "" }; var testData = data.ConcatWith(""); Console.WriteLine(testData); Console.WriteLine(""); using (var reader = new System.IO.StringReader(testData)) { var target = new XsvData <XsvDataRow>(new[] { sep, sep2 }); target.Read(reader); foreach (var row in target.Rows) { Console.WriteLine(row.ToString() + " <<"); } Console.WriteLine(""); foreach (var row in target.Rows) { Console.WriteLine(row.OutputFields(new[] { ":" }, ":") + " <<"); } var sb = new StringBuilder(); using (var writer = new StringWriter(sb)) { target.Write(writer); } Console.WriteLine("----------"); Console.WriteLine(sb.ToString()); } }