2

I have a long(ish) csv that I need to ingest into either a multi dimensional array or data table to be iterated over. The format is simple:

filepathX, sizeinbytes1 (i.e. C:\temp\yourfile.txt, 12345)

In straight .net I used the OleDb provider, however the Unity engine does not seem to play nice with this reference. I cannot use external libraries like FileHelpers.

2
  • 3
    Reading CSV is a tricky business. There is a reasonably popular parser available with downloadable source code distributed under MIT license, here is the link. Commented May 27, 2012 at 21:15
  • Out of curiosity when you say "didn't play nice" what issues did you see? It maybe easier to fix them than change the code base. Commented Dec 9, 2012 at 2:03

1 Answer 1

1

dasblinkenlight is right about CVS being (in general) non-trivial to parse, but you have described a VERY specific format.

Personlly, I'd just read the file line by line and use LastIndexOf(",") to split off the size - that at least will protect you from the possability that there's a comma in the file name.

Fianlly, do you really need it in an array or data table? You could wrap the file reading into your own iterator using "yield return" (return a custom struct or a Tuple if you're lazy!), and at least have "nice" code sitting on top doing the iteration.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.