summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authornabijaczleweli <nabijaczleweli@gmail.com>2016-09-12 01:26:45 +0200
committernabijaczleweli <nabijaczleweli@gmail.com>2016-09-12 01:33:02 +0200
commitd131963cfcb7047afa495fea697093bbe7d7741f (patch)
treeaa4471954287b56b7847167d8b59c77fffe5c2e4 /examples
parent7ea0205b9546da5b4754d79641a68605a72dd3b8 (diff)
Implement saving and loading from CSV
Closes #13
Diffstat (limited to 'examples')
-rw-r--r--examples/csv.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/examples/csv.rs b/examples/csv.rs
new file mode 100644
index 0000000..df14173
--- /dev/null
+++ b/examples/csv.rs
@@ -0,0 +1,26 @@
+extern crate prettytable;
+use prettytable::Table;
+
+/*
+ Following main function will print :
+ +---------+------+---------+
+ | ABC | DEFG | HIJKLMN |
+ +---------+------+---------+
+ | foobar | bar | foo |
+ +---------+------+---------+
+ | foobar2 | bar2 | foo2 |
+ +---------+------+---------+
+
+ ABC,DEFG,HIJKLMN
+ foobar,bar,foo
+ foobar2,bar2,foo2
+*/
+fn main() {
+ let table = Table::from_csv_string("ABC,DEFG,HIJKLMN\n\
+ foobar,bar,foo\n\
+ foobar2,bar2,foo2").unwrap();
+ table.printstd();
+
+ println!("");
+ println!("{}", table.to_csv(Vec::new()).unwrap().into_string());
+}