Replies: 1 comment
-
You could give this a try. I would test it on a few files and make sure the numbers are correct though. void Main()
{
var s = new StringBuilder();
s.AppendLine("Id,Name");
s.AppendLine("1,one");
s.AppendLine("2,two");
using (var reader = new StringReader(s.ToString()))
using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
{
var chars = 0;
var records = new List<Foo>();
csv.Read();
csv.ReadHeader();
chars += csv.Context.RawRecord.Length;
while (csv.Read())
{
chars += csv.Context.RawRecord.Length;
records.Add(csv.GetRecord<Foo>());
}
chars.Dump();
records.Dump();
}
}
public class Foo
{
public int Id { get; set; }
public string Name { get; set; }
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I just want to ask you if there is any possibilities to get the count of all characters in file during reading the CSV file? I don't want to load file into memory two times (one time for parsing, second time for counting).
I need to parse CSV file but also I need to get the number of all characters in this file (with delimeters). Someone has any idea how to do that in the most efficient way?
Thanks in Advance 👍
Beta Was this translation helpful? Give feedback.
All reactions