I need a CSV (comma-separated values) parser to use in my next project, in Unity (C#). I looked at existing parsers but all the ones I found were missing some features, or not available in source code.
I ported the simple but efficient parser I made in my mobile games to C# (was C++).
It’s available on Github here.
- commas inside cells
- quotes inside cells
- line breaks inside cells
- empty cells
- utf8 characters
I need all those features because I use csv mostly for localization. My latest game was ported to 11 languages (inclusing Chinese, Japanese and Russian) and I plan to support even more languages in the next one. I export the texts from a Google Doc sheet to csv.
How to use with Unity
Just use a TextAsset (csv files are recognized as text in Unity).
void MyReader(int line_index, List
// Will be called for each line parsed from the csv
TextAsset text_asset = Resources.Load("csv_file");
fgCSVReader.Load(text_asset.text, new fgCSVReader.ReadLineDelegate(MyReader));
It can be useful to stream the data when reading huge files. I don’t need it and it’s easier with Unity to read the whole file at once so I didn’t implement it.