Simple CSV/DSV importer
Powershell, 25 22/23 bytes
Two Options, one just calls split on the first arg, using the second arg as a delim value.
$args[0]-split$args[1]
One byte longer, builtin to parse csvs, takes filename as first arg and delim as second.
ipcsv $args[0] $args[1]
-2 because it doesn't require the -Delimiter
(-D
) param, and will assume it by default.
sadly powershell cannot pass an array of two params, as it will assume they are both files, and will run the command against it twice, no other two-var input method is shorter than this as far as I can see, so this is likely the shortest possible answer.
ipcsv
is an alias for Import-Csv
, takes a file name as the first unnamed input, and the delim character as the second by default behavior.
Run against the example from the wiki page returns
PS C:\Users\Connor\Desktop> .\csvparse.ps1 'example.csv' ','
Date Pupil Grade
---- ----- -----
25 May Bloggs, Fred C
25 May Doe, Jane B
15 July Bloggs, Fred A
15 April Muniz, Alvin "Hank" A
Japt, 3 bytes
mqV
Test it online! (Uses the -Q
flag to prettyprint the output)
mqV // Implicit: U, V = inputs
m // Map each item in U by the following function:
qV // Split the item at instances of V.
// Implicit: output result of last expression
Python, 33 bytes
lambda a,c:[x.split(c)for x in a]