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
5
votes
2 answers

How to split a string at the last occurence of a sequence

Target: A string with a built-in separator shall be split in an int and another string. In the case that the separator sequence '###' occurs more than once, the string shall always be spliced at the last '###'. Is there an operator like…
procra
  • 535
  • 4
  • 29
5
votes
1 answer

String split with multiple ending delimiter

I am trying to parse a csv file where some of the lines may have missing fields, and I found this strange behavior: scala> val s = "1,2,,," s: String = 1,2,,, scala> s.split(",") res4: Array[String] = Array(1, 2) While I am expecting the result to…
Psidom
  • 209,562
  • 33
  • 339
  • 356
5
votes
2 answers

unpacking a split inside a list comprehension

If I want to generate a list of tuples based on elements of lines of a document, i can do : [(line.split()[0], line.split()[-1][3:8]) for line in open("doc.txt")] for example (i added the slicing to show that I might want use some operations…
Ando Jurai
  • 1,003
  • 2
  • 14
  • 29
5
votes
5 answers

How to split a string into two arrays using explode-implode functions?

Suppose I have this following string : 5+6-5*3/2+4 I need to split the string into two arrays: first array containing the integers, second array containing the operators from the string. I have used the preg_split() function, like…
Tango Alpha
  • 157
  • 3
5
votes
2 answers

Split matrix and rejoin

This is my first post. Apologies in advance if my question is dumb. I'm new to programming. Ok, So I have a a matrix(eBpvalues) in R that has 152720 rows and 2 columns. I want to split into 10 separate matrices containing 15272 rows each. I have…
nrhorner
  • 328
  • 6
  • 16
5
votes
7 answers

Split an array dependent on the array values in Python

I have an array of coordinates like this: array = [[1,6],[2,6],[3,8],[4,10],[5,6],[5,7],[18,6],[19,5],[17,9],[10,5]] I want to split the array between 6. and 7. coordinate ([5,7],[18,6]) because there is a gap in the X value there. I want to get…
agrom
  • 386
  • 2
  • 5
  • 19
5
votes
1 answer

Split a pandas column into two based on a delimiter that may not exist on all values

One of the columns of my dataframe looks something like this: [application] blah/3.14 xyz/5.2 abc ... ... (representing software/version) I'm trying to achieve something like this: [application] [name] [ver] blah/3.14 blah 3.14 xyz/5.2 …
SloppyPenguin
  • 65
  • 1
  • 4
5
votes
4 answers

How to split a string into only positive and negative integers?

I'm writing a program to do different calculations with vector functions, but the program I have as of now delimits the negative digits. I've tried using different delimiters but I can't seem to get the right one. Does anyone know how to keep the…
user5553106
5
votes
2 answers

Splitting character string in R based on characters

I have a column in my dataset where there is a string of character that I want to split. df = data.frame(col = c("BrBkRY","BBkRBr","YBRG","RBBk")) This is the vector that I want to use to conditionally split. sep =…
M. Beausoleil
  • 3,141
  • 6
  • 29
  • 61
5
votes
5 answers

Split string before any first number

string test = " Puerto Rico 123 " ; I would like to obtain only "Puerto Rico". The idea is that instead of 123 it can be any number. How can I achieve this?
Florin M.
  • 2,159
  • 4
  • 39
  • 97
5
votes
1 answer

XSLT split output files - muenchian grouping

I have an XSLT file so as to transform large amount of data. I would like to add a "split" functionality, either as a chained XSLT or within the current XSLT that can create multiple output files so as to limit the size of the files under a certain…
Daniel
  • 165
  • 3
  • 12
5
votes
2 answers

How to get the first line in a paragraph

I am developing a iOS mobile app where my requirement is to get the first line of the paragraph and change its font from the rest of the paragraph. For e.g. - If I have a paragraph as - let sampleString = "IS1 This is sample text. This sample text…
bably
  • 1,065
  • 5
  • 17
  • 27
5
votes
6 answers

Split php content in multiple files

I have no idea if there's a technical term for this, so I didn't find anything on google nor this site. A friend of mine who has been making sites for years, and actually set up a bussiness, uses a rather unique (to me) system. He splits up his page…
Nick
  • 1,082
  • 1
  • 15
  • 27
5
votes
3 answers

T-SQL split on delimiter

I am working with an employee hierarchy string that is in the format of the following. These number represent employeeID numbers and how the are structured within the company, thus being able to follow the chain of management. …
SBB
  • 8,560
  • 30
  • 108
  • 223
5
votes
4 answers

Splitting a string on / when not within [ ]

I'm trying to split a string representing an XPath such as: string myPath = "/myns:Node1/myns:Node2[./myns:Node3=123456]/myns:Node4"; I need to split on '/' (the '/' excluded from results, as with a normal string split) unless the '/' happens to…
Code Stranger
  • 103
  • 1
  • 10
1 2 3
99
100