本文整理汇总了C#中CsvParser类的典型用法代码示例。如果您正苦于以下问题:C# CsvParser类的具体用法?C# CsvParser怎么用?C# CsvParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CsvParser类属于命名空间,在下文中一共展示了CsvParser类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: AllFieldsEmptyTest
public void AllFieldsEmptyTest()
{
using( var stream = new MemoryStream() )
using( var reader = new StreamReader( stream ) )
using( var writer = new StreamWriter( stream ) )
using( var parser = new CsvParser( reader ) )
{
writer.WriteLine( ";;;;" );
writer.WriteLine( ";;;;" );
writer.Flush();
stream.Position = 0;
parser.Configuration.Delimiter = ";;";
parser.Configuration.HasHeaderRecord = false;
var row = parser.Read();
Assert.IsNotNull( row );
Assert.AreEqual( 3, row.Length );
Assert.AreEqual( "", row[0] );
Assert.AreEqual( "", row[1] );
Assert.AreEqual( "", row[2] );
row = parser.Read();
Assert.IsNotNull( row );
Assert.AreEqual( 3, row.Length );
Assert.AreEqual( "", row[0] );
Assert.AreEqual( "", row[1] );
Assert.AreEqual( "", row[2] );
row = parser.Read();
Assert.IsNull( row );
}
}
开发者ID:KPK-Teamwork-Team-Bajic,项目名称:KPK-Teamwork,代码行数:33,代码来源:CsvParserDelimiterTests.cs
示例2: MultipleCharDelimiter2Test
public void MultipleCharDelimiter2Test()
{
using( var stream = new MemoryStream() )
using( var reader = new StreamReader( stream ) )
using( var writer = new StreamWriter( stream ) )
using( var parser = new CsvParser( reader ) )
{
writer.WriteLine( "1``2``3" );
writer.WriteLine( "4``5``6" );
writer.Flush();
stream.Position = 0;
parser.Configuration.Delimiter = "``";
parser.Configuration.HasHeaderRecord = false;
var row = parser.Read();
Assert.IsNotNull( row );
Assert.AreEqual( 3, row.Length );
Assert.AreEqual( "1", row[0] );
Assert.AreEqual( "2", row[1] );
Assert.AreEqual( "3", row[2] );
row = parser.Read();
Assert.IsNotNull( row );
Assert.AreEqual( 3, row.Length );
Assert.AreEqual( "4", row[0] );
Assert.AreEqual( "5", row[1] );
Assert.AreEqual( "6", row[2] );
row = parser.Read();
Assert.IsNull( row );
}
}
开发者ID:cihanozhan,项目名称:CsvHelper,代码行数:33,代码来源:CsvParserDelimiterTests.cs
示例3: ByteCountUsingCharWithMoreThanSingleByteTest
public void ByteCountUsingCharWithMoreThanSingleByteTest()
{
var encoding = Encoding.Unicode;
using( var stream = new MemoryStream() )
using( var writer = new StreamWriter( stream, encoding ) )
using( var reader = new StreamReader( stream, encoding ) )
using( var parser = new CsvParser( reader ) )
{
//崔钟铉
parser.Configuration.CountBytes = true;
parser.Configuration.Encoding = encoding;
writer.Write( "1,崔\r\n" );
writer.Write( "3,钟\r\n" );
writer.Write( "5,铉\r\n" );
writer.Flush();
stream.Position = 0;
parser.Read();
Assert.Equal( 8, parser.BytePosition );
parser.Read();
Assert.Equal( 18, parser.BytePosition );
parser.Read();
Assert.Equal( 28, parser.BytePosition );
parser.Read();
Assert.Equal( 30, parser.BytePosition );
}
}
开发者ID:paulduran,项目名称:CsvHelper,代码行数:30,代码来源:CsvParserTests.cs
示例4: Setup
public void Setup()
{
var parser = new CsvParser();
_singleLineParser = parser;
_parser = parser;
}
开发者ID:modulexcite,项目名称:Parsnip,代码行数:7,代码来源:Csv_Specs.cs
示例5: DifferentDelimiterTest
public void DifferentDelimiterTest()
{
using( var stream = new MemoryStream() )
using( var reader = new StreamReader( stream ) )
using( var writer = new StreamWriter( stream ) )
using( var parser = new CsvParser( reader ) )
{
writer.WriteLine( "1\t2\t3" );
writer.WriteLine( "4\t5\t6" );
writer.Flush();
stream.Position = 0;
parser.Configuration.Delimiter = "\t";
parser.Configuration.HasHeaderRecord = false;
var row = parser.Read();
Assert.IsNotNull( row );
Assert.AreEqual( 3, row.Length );
Assert.AreEqual( "1", row[0] );
Assert.AreEqual( "2", row[1] );
Assert.AreEqual( "3", row[2] );
row = parser.Read();
Assert.IsNotNull( row );
Assert.AreEqual( 3, row.Length );
Assert.AreEqual( "4", row[0] );
Assert.AreEqual( "5", row[1] );
Assert.AreEqual( "6", row[2] );
row = parser.Read();
Assert.IsNull( row );
}
}
开发者ID:cihanozhan,项目名称:CsvHelper,代码行数:33,代码来源:CsvParserDelimiterTests.cs
示例6: CallbackTest
public void CallbackTest()
{
using( var stream = new MemoryStream() )
using( var reader = new StreamReader( stream ) )
using( var writer = new StreamWriter( stream ) )
using( var parser = new CsvParser( reader ) )
{
writer.WriteLine( " a\"bc\",d" );
writer.WriteLine( "\"a\"\"b\"c \" ,d" );
writer.WriteLine( "\"a\"\"b\",c" );
writer.Flush();
stream.Position = 0;
string field = null;
parser.Configuration.BadDataCallback = f => field = f;
parser.Read();
Assert.IsNotNull( field );
Assert.AreEqual( " a\"bc\"", field );
field = null;
parser.Read();
Assert.IsNotNull( field );
Assert.AreEqual( "a\"bc \" ", field );
field = null;
parser.Read();
Assert.IsNull( field );
}
}
开发者ID:cihanozhan,项目名称:CsvHelper,代码行数:30,代码来源:ParserBadDataTests.cs
示例7: ByteCountTestWithQuotedFieldsClosingQuoteAtStartOfBuffer
public void ByteCountTestWithQuotedFieldsClosingQuoteAtStartOfBuffer()
{
var config = new Configuration.CsvConfiguration()
{
CountBytes = true,
BufferSize = 4
};
using( var stream = new MemoryStream() )
using( var writer = new StreamWriter( stream ) )
using( var reader = new StreamReader( stream ) )
using( var parser = new CsvParser( reader, config ) )
{
writer.Write( "1,\"2\",3\r\n" );
writer.Write( "\"4\",5,\"6\"\r\n" );
writer.Flush();
stream.Position = 0;
parser.Read();
Assert.AreEqual( 9, parser.BytePosition );
parser.Read();
Assert.AreEqual( 20, parser.BytePosition );
Assert.IsNull( parser.Read() );
}
}
开发者ID:KPK-Teamwork-Team-Bajic,项目名称:KPK-Teamwork,代码行数:27,代码来源:CsvParserTests.cs
示例8: CharReadTotalTest
public void CharReadTotalTest()
{
using( var stream = new MemoryStream() )
using( var writer = new StreamWriter( stream ) )
using( var reader = new StreamReader( stream ) )
using( var parser = new CsvParser( reader ) )
{
parser.Configuration.AllowComments = true;
// This is a breakdown of the char counts.
// Read() will read up to the first line end char
// and any more on the line will get read with the next read.
// [I][d][,][N][a][m][e][\r][\n]
// 1 2 3 4 5 6 7 8 9
// [1][,][o][n][e][\r][\n]
// 10 11 12 13 14 15 16
// [,][\r][\n]
// 17 18 19
// [\r][\n]
// 20 21
// [#][ ][c][o][m][m][e][n][t][s][\r][\n]
// 22 23 24 25 26 27 28 29 30 31 32 33
// [2][,][t][w][o][\r][\n]
// 34 35 36 37 38 39 40
// [3][,]["][t][h][r][e][e][,][ ][f][o][u][r]["][\r][\n]
// 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
writer.WriteLine( "Id,Name" );
writer.WriteLine( "1,one" );
writer.WriteLine( "," );
writer.WriteLine( "" );
writer.WriteLine( "# comments" );
writer.WriteLine( "2,two" );
writer.WriteLine( "3,\"three, four\"" );
writer.Flush();
stream.Position = 0;
parser.Read();
Assert.Equal( 8, parser.Position );
parser.Read();
Assert.Equal( 15, parser.Position );
parser.Read();
Assert.Equal( 18, parser.Position );
parser.Read();
Assert.Equal( 39, parser.Position );
parser.Read();
Assert.Equal( 56, parser.Position );
parser.Read();
Assert.Equal( 57, parser.Position );
}
}
开发者ID:anuragc64,项目名称:CsvHelper,代码行数:57,代码来源:CsvParserTests.cs
示例9: Parse
public static string[][] Parse(string input)
{
CsvParser parser = new CsvParser();
using (StringReader reader = new StringReader(input))
{
return parser.Parse(reader);
}
}
开发者ID:Rgallouet,项目名称:Blue-Star,代码行数:9,代码来源:CsvParser2.cs
示例10: Test
public void Test()
{
var data = CsvReaderSampleData.SampleData1;
var reader = new StringReader(data);
var parser = new CsvParser(reader, new CsvLayout(), new CsvBehaviour());
foreach (var line in parser)
{
}
}
开发者ID:jhgbrt,项目名称:netcsv,代码行数:10,代码来源:CsvParserTest.cs
示例11: EnsureInternalsAreSetupWhenPassingReaderAndConfigTest
public void EnsureInternalsAreSetupWhenPassingReaderAndConfigTest()
{
using( var stream = new MemoryStream() )
using( var reader = new StreamReader( stream ) )
{
var config = new CsvConfiguration();
using( var parser = new CsvParser( reader, config ) )
{
Assert.Same( config, parser.Configuration );
}
}
}
开发者ID:kharnt0x,项目名称:CsvHelper,代码行数:12,代码来源:CsvParserConstructorTests.cs
示例12: GetCkecklist
public IEnumerable<CheckListDto> GetCkecklist()
{
Assembly assembly = Assembly.GetExecutingAssembly();
string resourceName = string.Concat(assembly.GetName().Name, '.', FILE_NAME);
Stream stream = assembly.GetManifestResourceStream(resourceName);
CsvParser<CheckListDto> parser = new CsvParser<CheckListDto>(stream);
this.list = parser.Parse().ToList();
return list;
}
开发者ID:ohalay,项目名称:Checklist,代码行数:13,代码来源:ChecklistRepository.cs
示例13: EnsureInternalsAreSetupCorrectlyWhenPassingParserTest
public void EnsureInternalsAreSetupCorrectlyWhenPassingParserTest()
{
using( var stream = new MemoryStream() )
using( var reader = new StreamReader( stream ) )
{
var parser = new CsvParser( reader );
using( var csv = new CsvReader( parser ) )
{
Assert.Same( csv.Configuration, csv.Parser.Configuration );
Assert.Same( parser, csv.Parser );
}
}
}
开发者ID:rdingwall,项目名称:CsvHelper,代码行数:14,代码来源:CsvReaderConstructorTests.cs
示例14: TestNonDefaultRowDelimiterReading
public void TestNonDefaultRowDelimiterReading()
{
var settings = new CsvSettings() { RowDelimiter = "|" }; // also note, that it is single-char, not double char like default.
const String csv = "1,2,3|4,\"| as data\",\n\r as data|7";
using (var parser = new CsvParser(csv, settings))
{
String[][] rows = parser.ReadToEnd();
Assert.AreEqual(3, rows.Length, "Incorrect number of rows");
CollectionAssert.AreEqual(rows[0], new string[] { "1", "2", "3" });
CollectionAssert.AreEqual(rows[1], new string[] { "4", "| as data", "\n\r as data" });
CollectionAssert.AreEqual(rows[2], new string[] { "7" });
}
}
开发者ID:appleorange1,项目名称:Utilities.Csv,代码行数:15,代码来源:CustomisedSettingsTests.cs
示例15: Main
static void Main(string[] args)
{
CsvParser parser = new CsvParser();
parser.Go();
for (int i = 0; i < 5000000; i++)
GradDown(parser.Games);
PrintAverageError(parser);
foreach (Player p in parser.Players.Where(x => x.Quality != 0).OrderByDescending(x => x.Quality))
Console.WriteLine("{0, 11} {1, 5}", p.Name, p.Quality.ToString("0.00"));
//Console.WriteLine("{0},{1}", p.Name, p.Quality.ToString("0.00"));
Console.ReadLine();
}
开发者ID:JasonCrease,项目名称:FootballDescent,代码行数:16,代码来源:Program.cs
示例16: TestNonDefaultFieldDelimiterReading
public void TestNonDefaultFieldDelimiterReading()
{
var settings = new CsvSettings() { FieldDelimiter = '\t' };
const String csv = @"1 2 3
4 "" as data"" , as data
7";
using (var parser = new CsvParser(csv, settings))
{
String[][] rows = parser.ReadToEnd();
Assert.AreEqual(3, rows.Length, "Incorrect number of rows");
CollectionAssert.AreEqual(rows[0], new string[] { "1", "2", "3" });
CollectionAssert.AreEqual(rows[1], new string[] { "4", " as data", ", as data" });
CollectionAssert.AreEqual(rows[2], new string[] { "7" });
}
}
开发者ID:appleorange1,项目名称:Utilities.Csv,代码行数:17,代码来源:CustomisedSettingsTests.cs
示例17: CallingReadMultipleTimesAfterDoneReadingTest
public void CallingReadMultipleTimesAfterDoneReadingTest()
{
var stream = new MemoryStream();
var writer = new StreamWriter( stream );
writer.WriteLine( "one,two,three" );
writer.WriteLine( "four,five,six" );
writer.Flush();
stream.Position = 0;
var reader = new StreamReader( stream );
var parser = new CsvParser( reader );
parser.Read();
parser.Read();
parser.Read();
parser.Read();
}
开发者ID:heinrichbreedt,项目名称:CsvHelper,代码行数:17,代码来源:CsvParserTests.cs
示例18: ParseInvalidSpace1FieldSpaceBeforeEqualsTest
public void ParseInvalidSpace1FieldSpaceBeforeEqualsTest()
{
using( var stream = new MemoryStream() )
using( var writer = new StreamWriter( stream ) )
using( var reader = new StreamReader( stream ) )
using( var parser = new CsvParser( reader ) )
{
writer.Write( " =\"01\"\r\n" );
writer.Flush();
stream.Position = 0;
parser.Configuration.UseExcelLeadingZerosFormatForNumerics = true;
var row = parser.Read();
Assert.AreEqual( " =\"01\"", row[0] );
}
}
开发者ID:ravensorb,项目名称:CsvHelper,代码行数:17,代码来源:LeadingZeroTests.cs
示例19: ParseValid1FieldNoLineEndingTest
public void ParseValid1FieldNoLineEndingTest()
{
using( var stream = new MemoryStream() )
using( var writer = new StreamWriter( stream ) )
using( var reader = new StreamReader( stream ) )
using( var parser = new CsvParser( reader ) )
{
writer.Write( "=\"01\"" );
writer.Flush();
stream.Position = 0;
parser.Configuration.UseExcelLeadingZerosFormatForNumerics = true;
parser.Configuration.HasHeaderRecord = false;
var row = parser.Read();
Assert.AreEqual( "01", row[0] );
}
}
开发者ID:cihanozhan,项目名称:CsvHelper,代码行数:18,代码来源:LeadingZeroTests.cs
示例20: Parse1RecordWithNoCrlfTest
public void Parse1RecordWithNoCrlfTest()
{
using( var memoryStream = new MemoryStream() )
using( var streamReader = new StreamReader( memoryStream ) )
using( var streamWriter = new StreamWriter( memoryStream ) )
using( var parser = new CsvParser( streamReader ) )
{
streamWriter.Write( "one,two,three" );
streamWriter.Flush();
memoryStream.Position = 0;
var record = parser.Read();
Assert.IsNotNull( record );
Assert.AreEqual( 3, record.Length );
Assert.AreEqual( "one", record[0] );
Assert.AreEqual( "two", record[1] );
Assert.AreEqual( "three", record[2] );
}
}
开发者ID:heinrichbreedt,项目名称:CsvHelper,代码行数:19,代码来源:CsvParserTests.cs
注:本文中的CsvParser类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论