is there any way to read a csv file into a matrix, so every square in the file will be a cell in the matrix?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
There are many ways. Starting with a byte by byte reader. It depends on your csv file format (with/without header, line endings, " or '). I've written my own class.
A good reader to start with:
http://www.stellman-greene.com/CSVReader/
There are many open source CSV readers, and it's also easy to code your own.
For a start take look at codeplex.com: http://kbcsv.codeplex.com/
Or Codeproject tutorials: http://www.codeproject.com/KB/database/CsvReader.aspx
For sake of completion, here is my own utility class to read a line from a CSV file:
To make the matrix (untested):
CSV parsing with regular expressions: http://www.hotblue.com/article0000.aspx?a=0006
To expand the concept with custom separators, see this post: How do I write a regex to match a string that doesn't contain a word?
There is a text reader in the VisualBasic namespace that can be used in C# and handles even horrible CSV files very well:
TextFieldParser
Just add a reference to
Microsoft.VisualBasic
in your project.