Zig
Zig
CSV Enable Quotes
Explains the EnableQuotes property for the CSV class.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// The CSV in this example contains this: test;"123;abc";xyz
const csv = try chilkat.Csv.init();
defer csv.deinit();
// EnableQuotes is true by default, but we'll explicitly set to true here:
csv.setEnableQuotes(true);
try csv.loadFile("qa_data/csv/enableQuotes.csv");
// Show row 0, column 0
std.debug.print("{s}\n", .{try csv.getCell(alloc, 0, 0)});
// Show row 0, column 1
std.debug.print("{s}\n", .{try csv.getCell(alloc, 0, 1)});
// Show row 0, column 2
std.debug.print("{s}\n", .{try csv.getCell(alloc, 0, 2)});
// Output is:
// test
// 123;abc
// xyz
// -------------------------------------------
// Turn off EnableQuotes and see what happens:
const csv2 = try chilkat.Csv.init();
defer csv2.deinit();
csv2.setEnableQuotes(false);
try csv2.loadFile("qa_data/csv/enableQuotes.csv");
std.debug.print("{s}\n", .{try csv2.getCell(alloc, 0, 0)});
std.debug.print("{s}\n", .{try csv2.getCell(alloc, 0, 1)});
std.debug.print("{s}\n", .{try csv2.getCell(alloc, 0, 2)});
std.debug.print("{s}\n", .{try csv2.getCell(alloc, 0, 3)});
// Output is:
// test
// "123
// abc"
// xyz
}