{"id":1761,"date":"2015-08-31T18:23:51","date_gmt":"2015-08-31T18:23:51","guid":{"rendered":"http:\/\/www.frozax.com\/blog\/?p=1761"},"modified":"2015-08-31T18:23:51","modified_gmt":"2015-08-31T18:23:51","slug":"csharp-csv-reader-unity","status":"publish","type":"post","link":"https:\/\/www.frozax.com\/blog\/2015\/08\/csharp-csv-reader-unity\/","title":{"rendered":"C# CSV Reader (compatible with unity)"},"content":{"rendered":"<h1>Why?<\/h1>\n<p>I need a CSV (<a href=\"https:\/\/en.wikipedia.org\/wiki\/Comma-separated_values\">comma-separated values<\/a>) 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.<br \/>\nI ported the simple but efficient parser I made in my mobile games to C# (was C++). <\/p>\n<p>It&#8217;s available on <a href=\"https:\/\/github.com\/frozax\/fgCSVReader\">Github here<\/a>.<\/p>\n<h1>Features<\/h1>\n<ul>\n<li>commas inside cells<\/li>\n<li>quotes inside cells<\/li>\n<li>line breaks inside cells<\/li>\n<li>empty cells<\/li>\n<li>utf8 characters<\/li>\n<\/ul>\n<p>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.<\/p>\n<h1>How to use with Unity<\/h1>\n<p>Just use a TextAsset (csv files are recognized as text in Unity).<br \/>\n<code><br \/>\nvoid MyReader(int line_index, List<string> line)<br \/>\n{<br \/>\n    \/\/ Will be called for each line parsed from the csv<br \/>\n    ...<br \/>\n}<\/p>\n<p>TextAsset text_asset = Resources.Load(\"csv_file\");<br \/>\nfgCSVReader.Load(text_asset.text, new fgCSVReader.ReadLineDelegate(MyReader));<br \/>\n<\/code><\/p>\n<h1>Improvements<\/h1>\n<p>It can be useful to stream the data when reading huge files. I don&#8217;t need it and it&#8217;s easier with Unity to read the whole file at once so I didn&#8217;t implement it.<\/p>\n<h1>License<\/h1>\n<p>Feel free to use\/improve\/share\/update the <a href=\"https:\/\/github.com\/frozax\/fgCSVReader\">code<\/a> as you wish.<br \/>\nSend me a tweet <a href=\"http:\/\/twitter.com\/Frozax\">@Frozax<\/a> if you like it.<\/p>\n<div class=\"addtoany_share_save_container addtoany_content_bottom\"><div class=\"a2a_kit a2a_kit_size_32 addtoany_list a2a_target\" id=\"wpa2a_1\"><a class=\"a2a_button_twitter\" href=\"http:\/\/www.addtoany.com\/add_to\/twitter?linkurl=https%3A%2F%2Fwww.frozax.com%2Fblog%2F2015%2F08%2Fcsharp-csv-reader-unity%2F&amp;linkname=C%23%20CSV%20Reader%20%28compatible%20with%20unity%29\" title=\"Twitter\" rel=\"nofollow\" target=\"_blank\"><\/a><a class=\"a2a_button_facebook\" href=\"http:\/\/www.addtoany.com\/add_to\/facebook?linkurl=https%3A%2F%2Fwww.frozax.com%2Fblog%2F2015%2F08%2Fcsharp-csv-reader-unity%2F&amp;linkname=C%23%20CSV%20Reader%20%28compatible%20with%20unity%29\" title=\"Facebook\" rel=\"nofollow\" target=\"_blank\"><\/a><a class=\"a2a_button_google_plus\" href=\"http:\/\/www.addtoany.com\/add_to\/google_plus?linkurl=https%3A%2F%2Fwww.frozax.com%2Fblog%2F2015%2F08%2Fcsharp-csv-reader-unity%2F&amp;linkname=C%23%20CSV%20Reader%20%28compatible%20with%20unity%29\" title=\"Google+\" rel=\"nofollow\" target=\"_blank\"><\/a><a class=\"a2a_button_reddit\" href=\"http:\/\/www.addtoany.com\/add_to\/reddit?linkurl=https%3A%2F%2Fwww.frozax.com%2Fblog%2F2015%2F08%2Fcsharp-csv-reader-unity%2F&amp;linkname=C%23%20CSV%20Reader%20%28compatible%20with%20unity%29\" title=\"Reddit\" rel=\"nofollow\" target=\"_blank\"><\/a>\n<script type=\"text\/javascript\"><!--\nwpa2a.script_load();\n\/\/--><\/script>\n<\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Why? 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++).&hellip; <a class=\"more-link\" href=\"https:\/\/www.frozax.com\/blog\/2015\/08\/csharp-csv-reader-unity\/\">Continue reading <span class=\"screen-reader-text\">C# CSV Reader (compatible with unity)<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[12],"tags":[61,149],"_links":{"self":[{"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/posts\/1761"}],"collection":[{"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/comments?post=1761"}],"version-history":[{"count":12,"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/posts\/1761\/revisions"}],"predecessor-version":[{"id":1773,"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/posts\/1761\/revisions\/1773"}],"wp:attachment":[{"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/media?parent=1761"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/categories?post=1761"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/tags?post=1761"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}