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
150
votes
6 answers

Split comma-separated strings in a column into separate rows

I have a data frame, like so: data.frame(director = c("Aaron Blaise,Bob Walker", "Akira Kurosawa", "Alan J. Pakula", "Alan Parker", "Alejandro Amenabar", "Alejandro Gonzalez Inarritu", "Alejandro…
RoyalTS
  • 9,545
  • 12
  • 60
  • 101
150
votes
3 answers

Split string at every position where an upper-case word starts

What is the best way to split a string like "HELLO there HOW are YOU" by upper-case words? So I'd end up with an array like such: results = ['HELLO there', 'HOW are', 'YOU'] I have tried: p = re.compile("\b[A-Z]{2,}\b") print p.split(page_text) It…
user179169
148
votes
12 answers

Split string into array of character strings

I need to split a String into an array of single character Strings. Eg, splitting "cat" would give the array "c", "a", "t"
Matt
  • 11,157
  • 26
  • 81
  • 110
148
votes
5 answers

Pandas split DataFrame by column value

I have DataFrame with column Sales. How can I split it into 2 based on Sales value? First DataFrame will have data with 'Sales' < s and second with 'Sales' >= s
146 percent Russian
  • 2,016
  • 2
  • 14
  • 20
147
votes
7 answers

Javascript split regex question

hello I am trying what I thought would be a rather easy regex in Javascript but is giving me lots of trouble. I want the ability to split a date via javascript splitting either by a '-','.','/' and ' '. var date = "02-25-2010"; var myregexp2 = new…
Craig
  • 3,043
  • 8
  • 24
  • 25
143
votes
5 answers

How to split large text file in windows?

I have a log file with size of 2.5 GB. Is there any way to split this file into smaller files using windows command prompt?
Albin
  • 1,929
  • 2
  • 14
  • 18
142
votes
15 answers

string to string array conversion in java

I have a string = "name"; I want to convert into a string array. How do I do it? Is there any java built in function? Manually I can do it but I'm searching for a java built in function. I want an array where each character of the string will be a…
riyana
  • 21,385
  • 10
  • 35
  • 34
140
votes
13 answers

Splitting dataframe into multiple dataframes

I have a very large dataframe (around 1 million rows) with data from an experiment (60 respondents). I would like to split the dataframe into 60 dataframes (a dataframe for each participant). In the dataframe, data, there is a variable called…
Martin Petri Bagger
  • 2,187
  • 4
  • 17
  • 20
137
votes
11 answers

How can I maximize a split window?

Invoking :help in Vim, I got the help manual page with split window. I want to maximize the help manual window and close the other window. How can I do this? What is the Vim command to do this?
cola
  • 12,198
  • 36
  • 105
  • 165
136
votes
16 answers

A method to reverse effect of java String.split()?

I am looking for a method to combine an array of strings into a delimited String. An opposite to split(). Wanted to ask the forum before I try writing my own (since the JDK has everything)
javaphild
  • 1,511
  • 3
  • 12
  • 6
136
votes
5 answers

Split list into multiple lists with fixed number of elements

How to split a List of elements into lists with at most N items? ex: Given a list with 7 elements, create groups of 4, leaving the last group possibly with less elements. split(List(1,2,3,4,5,6,"seven"),4) => List(List(1,2,3,4), List(5,6,"seven"))
Johnny Everson
  • 8,343
  • 7
  • 39
  • 75
135
votes
14 answers

Split value from one field to two

I've got a table field membername which contains both the last name and the first name of users. Is it possible to split those into 2 fields memberfirst, memberlast? All the records have this format "Firstname Lastname" (without quotes and a space…
tsiger
  • 1,607
  • 2
  • 15
  • 16
134
votes
16 answers

Regex for splitting a string using space when not surrounded by single or double quotes

I'm new to regular expressions and would appreciate your help. I'm trying to put together an expression that will split the example string using all spaces that are not surrounded by single or double quotes. My last attempt looks like this: (?!")…
carlsz
  • 2,224
  • 3
  • 18
  • 16
133
votes
16 answers

How does strtok() split the string into tokens in C?

Please explain to me the working of strtok() function. The manual says it breaks the string into tokens. I am unable to understand from the manual what it actually does. I added watches on str and *pch to check its working when the first while loop…
user379888
131
votes
3 answers

How can I split and parse a string in Python?

I am trying to split this string in python: 2.7.0_bf4fda703454 I want to split that string on the underscore _ so that I can use the value on the left side.
kamal
  • 9,637
  • 30
  • 101
  • 168