Slightly more than an inverse of this.

In: Multi-line DSV data and a single delimiter character. The DSV may be taken as a file, a filename, line-break separated string, list of strings, etc. All records have the same number of fields, and no field is empty. Data does not contain the delimiter character and there is no quoting or escaping mechanism.

Out: A data structure representing the DSV, e.g. a list of lists of strings or a matrix of strings.


["here is,some,sample","data,delimited,by commas"] and ",":
[["here is","some","sample"],["data","delimited","by commas"]]

["hello;\"","\";world","\";\""] and ";":
[["hello","\""],["\"","world"],["\"","\""]] (escapes because this example uses JSON)

["to be or not","that is the question"] and " ":

  • \$\begingroup\$ So just to clarify, we simply split each item at instances of the given char? \$\endgroup\$ – ETHproductions Feb 28 '17 at 19:42
  • \$\begingroup\$ @ETHproductions That's right. \$\endgroup\$ – Adám Feb 28 '17 at 19:45
  • \$\begingroup\$ How should we split the strings if the first or last character is the delimiter? ",for,example,this,string," \$\endgroup\$ – G B Mar 1 '17 at 10:28
  • \$\begingroup\$ @GB no field is empty \$\endgroup\$ – Adám Mar 1 '17 at 10:35
  • \$\begingroup\$ So we can assume it won't happen? \$\endgroup\$ – G B Mar 1 '17 at 10:42

18 Answers 18


Jelly, 3 2 bytes

Dennis points out that while the 2 byte solution appears to not work, the dyadic link itself does, and that it is actually the way command line arguments are parsed that make it look that way.


Try It Online! - footer calls the function with left and right set explicitly, and formats as a grid*.

Exactly as the below, except splits at occurrences of the right argument rather than at sublists equal to the right argument.


The 3 byter - footer displays the result as a grid*.

A dyadic link (function) that takes the DSV list on the left and the delimiter on the right.


œṣ€ - Main link: list l, delimiter d
  € - for each item in l:
œṣ  -     split at occurrences of sublists equal to d

* As a full program the implicit output would simply "smush" together all the characters, so the footer of the TIO link calls the link as a dyad and uses G to format the result nicely.

  • \$\begingroup\$ @Okx the implicit output would simply "smush" together all the characters \$\endgroup\$ – Adám Feb 28 '17 at 19:48
  • \$\begingroup\$ @Okx Yes it is a function that returns a list. The footer is to override the implicit output that occurs when it is run as a full program. \$\endgroup\$ – Jonathan Allan Feb 28 '17 at 19:48

Japt, 3 bytes


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
  • \$\begingroup\$ :O a JSGL beat MATL! \$\endgroup\$ – Downgoat Mar 1 '17 at 3:18

Powershell, 25 22/23 bytes

Two Options, one just calls split on the first arg, using the second arg as a delim value.


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

Python, 33 bytes

lambda a,c:[x.split(c)for x in a]

Haskell, 29 bytes

import Data.Lists

Usage example: (map.splitOn) " " ["to be or not","that is the question"] -> [["to","be","or","not"],["that","is","the","question"]].


05AB1E, 5 bytes


Try it online!


v     For each element in the input array
 y    Push the element
  ²   Push second input
   ¡  Split
    ˆ Add to array

JavaScript, 26 bytes


Receives input in format (array of strings)(delimiter)

Try it online!


Mathematica, 11 bytes


Builtin function taking two arguments, a list of strings and a character (and even more general than that). Example usage:

StringSplit[{"to be or not", "that is the question"}, " "]


{{"to", "be", "or", "not"}, {"that", "is", "the", "question"}}

MATLAB / Octave, 41 25 bytes


Creates an anonymous function named ans which accepts the first input as a cell array of strings and the second input as a string.

ans({'Hello World', 'How are you'}, ' ')

Try it Online


Cheddar, 19 bytes


nice demonstration of looping abilities. I added new composition and f.op. blocks so that allows for interesting golfing. (=>:@.split) is supposed to work but it doesn't :(


MATL, 14 12 4 bytes


Try it at MATL Online (the link has a modification at the end to show the dimensionality of the output cell array).


        % Implicitly grab the first input as a cell array of strings
        % Implicitly grab the delimiter as a string
H       % Push the number literal 2 to the stack
&XX     % Split the input at each appearance of the delimiter
        % Implicitly display the result

CJam, 5 bytes



l~     e#Input evaluated (as list)
  l    e#Another line of input
   ./  e#Split first input by second

Ruby using '-n', 17+1 = 18 bytes

p chomp.split *$*

How it works

  • Input from file
  • separator is given as command line parameter
  • since we only have 1 parameter, *$* splats the string and we can use it as a parameter for the split function
  • I tried to avoid chomp but any other solution seems to be longer than this.

Rebol, 33 bytes

func[b s][map-each n b[split n s]

GNU sed, 48 + 1(r flag) = 49 bytes


Try it online!

In sed there are no data types, but a natural representation of a list would be a collection of lines. As such, the input format consists of DSV records each on a separate line, with the delimiter present on the first line.

Explanation: by design, sed runs the script as many times as there are input lines

1h;1d                  # store delimiter, start new cycle
:                      # begin loop
G                      # append saved delimiter
/,$/bp                 # if delimiter is ',', skip replacements and go to printing
s:(.)(.*)\n\1:,\2:     # replace first occurrence of delimiter with ','
t                      # repeat
:p;s:..$::             # print label: delete appended delimiter (implicit printing)

REXX, 95 bytes

arg f d
do l=1 while lines(f)
    do #=1 while n>''
        parse var n w (d) n

Takes a filename and a delimiter as arguments, contents of file are put in stem o.

  • \$\begingroup\$ Is all that whitespace really necessary? \$\endgroup\$ – Adám Mar 29 '17 at 8:03
  • \$\begingroup\$ No, I only indented it for readability. The byte count is for unindented code. \$\endgroup\$ – idrougge Mar 29 '17 at 9:03
  • \$\begingroup\$ Which flavour of REXX is this? \$\endgroup\$ – Adám Mar 29 '17 at 9:39
  • \$\begingroup\$ I think it's pure ANSI REXX. I've only tested it with Regina. \$\endgroup\$ – idrougge Mar 29 '17 at 11:02
  • 1
    \$\begingroup\$ On its way to TIO... \$\endgroup\$ – Adám Mar 29 '17 at 11:04

APL (Dyalog), 4 bytes

In versions up to and including 15.0, this needs ⎕ML←3 which is default by many. From version 16.0 can just be replaced by for the same effect.

Takes separator as left argument and DSV as right argument.


Try it online!

 the inequalities (of the left argument and the right argument)

⊂¨ partition each

 right argument

By partition is mean to remove all elements indicated by a corresponding zero in the left argument, and begin a new partition whenever a the corresponding number in the left argument is greater than its predecessor, i.e. on every one if the left argument is Boolean, as is the case here.


R, 8 bytes (2 ways)

R has two builtin functions that meet the requirements of this challenge:


takes a vector of strings and a separator, and returns a list of vectors of the separated strings.


takes a file name and a separator, and returns a data frame. Technically this might be 10 bytes because it needs the option header=F so it won't read the first elements as the column names. Currently the TIO link reads from stdin.

Try these online!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.