Questions tagged [split]

Use this tag for questions about separating an item (e.g. a string) into parts, often by a delimiter or regular expression.

It is most often applied when splitting a string by a delimiter, such as when parsing a comma separated value file. Some languages such as Ruby and Java support splitting a string according to regular expression as well.

A split string produces an array of strings.

split can also refer to

  1. the split function
  2. the String#split method
  3. the str.split method
  4. the explode function.
  5. the split method
  6. the split method
  7. the // String.Split method
  8. the / split command line utility
  9. the STRING_SPLIT function

All these functions/methods split strings on a delimiter.

The split function in divides data into groups by a specified factor.

24261 questions
83 answers

How do I iterate over the words of a string?

How do I iterate over the words of a string composed of words separated by whitespace? Note that I'm not interested in C string functions or that kind of character manipulation/access. I prefer elegance over efficiency. My current solution: #include…
Ashwin Nanjappa
  • 76,204
  • 83
  • 211
  • 292
69 answers

How do I split a list into equally-sized chunks?

How do I split a list of arbitrary length into equal sized chunks? See also: How to iterate over a list in chunks. To chunk strings, see Split string every nth character?.
  • 32,466
  • 3
  • 23
  • 12
38 answers

How do I split a string on a delimiter in Bash?

I have this string stored in a variable: IN=";" Now I would like to split the strings by ; delimiter so that I have: ADDR1="" ADDR2="" I don't necessarily need the ADDR1 and ADDR2 variables. If…
  • 77,323
  • 27
  • 116
  • 141
38 answers

How do I split a string in Java?

I want to split the string "004-034556" into two strings by the delimiter "-": part1 = "004"; part2 = "034556"; That means the first string will contain the characters before '-', and the second string will contain the characters after '-'. I also…
  • 21,385
  • 10
  • 35
  • 34
80 answers

Split array into chunks

Let's say that I have an Javascript array looking as following: ["Element 1","Element 2","Element 3",...]; // with close to a hundred elements. What approach would be appropriate to chunk (split) the array into many smaller arrays with, lets say,…
  • 41,400
  • 69
  • 194
  • 289
17 answers

split a string on newlines in .NET

I need to split a string into newlines in .NET and the only way I know of to split strings is with the Split method. However that will not allow me to (easily) split on a newline, so what is the best way to do it?
  • 38,647
  • 50
  • 150
  • 207
25 answers

How to split a string into an array in Bash?

In a Bash script, I would like to split a line into pieces and store them in an array. For example, given the line: Paris, France, Europe I would like to have the resulting array to look like so: array[0] = Paris array[1] = France array[2] =…
  • 9,581
  • 5
  • 20
  • 26
19 answers

How can I convert a comma-separated string to an array?

I have a comma-separated string that I want to convert into an array, so I can loop through it. Is there anything built-in to do this? For example, I have this string var str =…
  • 259,732
  • 324
  • 769
  • 1,199
11 answers

Split a string by another string in C#

I've been using the Split() method to split strings, but this only appears to work if you are splitting a string by a character. Is there a way to split a string, with another string being the split by parameter? I've tried converting the splitter…
  • 8,743
  • 2
  • 20
  • 16
31 answers

Split Strings into words with multiple word boundary delimiters

I think what I want to do is a fairly common task but I've found no reference on the web. I have text with punctuation, and I want a list of the words. "Hey, you - what are you doing here!?" should be ['hey', 'you', 'what', 'are', 'you', 'doing',…
  • 16,259
  • 13
  • 37
  • 32
41 answers

Split a String into an array in Swift?

Say I have a string here: var fullName: String = "First Last" I want to split the string base on white space and assign the values to their respective variables var fullNameArr = // something like: fullName.explode(" ") var firstName: String =…
  • 12,165
  • 10
  • 34
  • 41
5 answers

Split string with multiple delimiters in Python

I found some answers online, but I have no experience with regular expressions, which I believe is what is needed here. I have a string that needs to be split by either a ';' or ', ' That is, it has to be either a semicolon or a comma followed by a…
  • 7,755
  • 3
  • 16
  • 9
25 answers

How do I split a string with multiple separators in JavaScript?

How do I split a string with multiple separators in JavaScript? I'm trying to split on both commas and spaces, but AFAIK JavaScript's split() function only supports one separator.
8 answers

To switch from vertical split to horizontal split fast in Vim

How can you switch your current windows from horizontal split to vertical split and vice versa in Vim? I did that a moment ago by accident but I cannot find the key again.
Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697
28 answers

How to convert comma-separated String to List?

Is there any built-in method in Java which allows us to convert comma separated String to some container (e.g array, List or Vector)? Or do I need to write custom code for that? String commaSeparated = "item1 , item2 , item3"; List items =…
  • 21,150
  • 37
  • 80
  • 107
2 3
99 100