Re: [Vala] open and read a csv file
- From: Al Thomas <astavale yahoo co uk>
- To: vala-list <vala-list gnome org>
- Subject: Re: [Vala] open and read a csv file
- Date: Thu, 16 Oct 2014 17:35:25 +0100
From: Jason Scurtu <scurtu mail de>
Sent: Thursday, 16 October 2014, 14:42
Subject: [Vala] open and read a csv file
Basicly, I want to open a csv and write the data to a SQLite database and display it in a GridView .. but,
how to read a CSV?
I come from a C# background and I can hardly find any doucumentation or a app that does something similar
(code peek).
Please, can someone help me get started. Would really apprieciate it.
I've had a quick look through ValaDoc ( http://valadoc.org/ ) and the Extras repository (
https://github.com/nemequ/vala-extra-vapis ) and can't see any bindings to a CSV parser. So you could
consider finding a C library for CSV parsing and writing a Vala API binding.
Alternatively parsing the file yourself could be an option. Use FileStream (
http://www.valadoc.org/#!api=glib-2.0/GLib.FileStream ) to open the file and read each line. Vala, from its
close dependency on GLib, includes a regex library. For an introduction see
http://ewgeny.wordpress.com/2012/04/07/mighty-perl-like-regular-expressions-regex-with-glib-and-vala/ , for
details see http://references.valadoc.org/#!api=glib-2.0/GLib.Regex or you can just use string split (
http://references.valadoc.org/#!api=glib-2.0/string.split )
Writing your own CSV parser can be harder work if you start getting into details of not splitting quoted
values. For a discussion see
http://stackoverflow.com/questions/1189416/c-regular-expressions-how-to-parse-comma-separated-values-where-some-values
Good luck,
Al
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]