本文整理汇总了C#中CsvWriter.WriteLine方法的典型用法代码示例。如果您正苦于以下问题:C# CsvWriter.WriteLine方法的具体用法?C# CsvWriter.WriteLine怎么用?C# CsvWriter.WriteLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CsvWriter
的用法示例。
在下文中一共展示了CsvWriter.WriteLine方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestNonDefaultRowDelimiterWriting
public void TestNonDefaultRowDelimiterWriting()
{
using (var writer = new StringWriter())
{
var csv = new CsvWriter(writer, new CsvSettings() { RowDelimiter = "|" });
csv.WriteLine("1", "2", "3");
csv.WriteLine("4", "5", "6");
const String expected = @"1,2,3|4,5,6|";
Assert.AreEqual(expected, writer.ToString());
}
}
示例2: TestWritingSimple
public void TestWritingSimple()
{
using (var writer = new StringWriter())
{
var csv = new CsvWriter(writer, new CsvSettings());
csv.WriteLine("1", "2", "3");
csv.WriteLine("4", "5", "6");
String expected = @"1,2,3" + Environment.NewLine + "4,5,6" + Environment.NewLine;
Assert.AreEqual(expected, writer.ToString());
}
}
示例3: TestWritingSpecialChars
public void TestWritingSpecialChars()
{
using (var writer = new StringWriter())
{
var csv = new CsvWriter(writer, new CsvSettings());
csv.WriteLine("simple", "\"", Environment.NewLine, ",");
String expected = "simple,\"\"\"\",\"\r\n\",\",\"" + Environment.NewLine;
Assert.AreEqual(expected, writer.ToString());
}
}
示例4: TestNonDefaultFieldDelimiterWriting
public void TestNonDefaultFieldDelimiterWriting()
{
using (var writer = new StringWriter())
{
var csv = new CsvWriter(writer, new CsvSettings() { FieldDelimiter = '\t' });
csv.WriteLine("1", "2", "3");
csv.WriteLine("4", "5", "6");
const String expected = @"1 2 3
4 5 6
";
Assert.AreEqual(expected, writer.ToString());
}
}
示例5: Main
static void Main(string[] args)
{
Console.WriteLine("Creating a single CSV file for each intSystemId in God..clasSystem");
Dictionary<int, string> systems = new Dictionary<int, string>();
DataTable t = new DataTable();
using (SqlCommand cmd = new SqlCommand("SELECT DISTINCT intId, strTitle FROM clasSystem"))
{
t = Database.ExecuteTable("Server=researchdb9; database=God; uid=sa; pwd=deter101; Min Pool Size=1; Max Pool Size=1000; Pooling=true; Connect Timeout=40000;packet size=4096", cmd);
}
foreach (DataRow r in t.Rows)
{
systems.Add((int)r[0], ((string)r[1]).Replace(@"\","").Replace(@"/",""));
}
foreach (int systemId in systems.Keys)
{
t = new DataTable();
using (SqlCommand cmd = new SqlCommand("SELECT s.strTitle, s.strDescription, s.bolCanBrowse, v.strValue, v.strDescription, v.intDepth, v.strParentValue, v.strTrimmedValue " +
"FROM clasValue v " +
" INNER JOIN clasSystem s ON s.intId = v.intSystemID " +
"WHERE intSystemID = @SystemId")
)
{
cmd.Parameters.AddWithValue("@SystemId", systemId);
t = Database.ExecuteTable("Server=researchdb9; database=God; uid=sa; pwd=deter101; Min Pool Size=1; Max Pool Size=1000; Pooling=true; Connect Timeout=40000;packet size=4096", cmd);
}
FileInfo f = new FileInfo(@"E:\Git\Atuk\SpendAnalysis\SQL\SourceFiles\" + systems[systemId].ToString() + ".csv");
Console.WriteLine(string.Format("Writing System {0}, {1}", systemId, systems[systemId]));
using (CsvWriter w = new CsvWriter(f.FullName))
{
w.WriteLine("strTitle, strDescription, bolCanBrowse, strValue, strDescription, intDepth, strParentValue, strTrimmedValue");
foreach (DataRow r in t.Rows)
{
w.WriteRecord(r);
}
}
}
}
示例6: TestNonDefaultQuotingCharacterWriting
public void TestNonDefaultQuotingCharacterWriting()
{
using (var writer = new StringWriter())
{
var csv = new CsvWriter(writer, new CsvSettings() { QuotingCharacter = '\'' });
csv.WriteLine("1", ",", Environment.NewLine);
csv.WriteLine("'quotesAsData'");
const String expected = @"1,',','
'
'''quotesAsData'''
";
Assert.AreEqual(expected, writer.ToString());
}
}