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
3 answers

Split a string at the last occurrence of the separator in golang

I am trying to split a string by the last occurrence of a separator (/) in golang Example, I have a string "a/b/c/d", after performing the split, I would like an array of string as below [ "a/b/c", "a/b" "a" ] I tried exploring strings package but…
DoIt
  • 3,270
  • 9
  • 51
  • 103
5
votes
1 answer

How do I split a data frame among columns, say at every nth column?

Let's say I am working with the following data frame: Mydata <- data.frame(X1 = c(1,2,3,4,5,6,7,8,9,10),X2 = c(1,3,1,1,1,5,1,1,8,1), X3 = c(1,2,3,4,5,6,7,8,9,10),X4 = c(1,3,1,1,1,5,1,1,8,1), X5 =…
5
votes
4 answers

remove numbers from beginning of a line in a string with PHP

I have a bunch of strings in php that all look like this: 10 NE HARRISBURG 4 E HASWELL 2 SE OAKLEY 6 SE REDBIRD PROVO 6 W EADS 21 N HARRISON What I am needing to do is remove the numbers and the letters from before the city names. The problem I am…
shinjuo
  • 20,498
  • 23
  • 73
  • 104
5
votes
7 answers

Create array of strings from a larger string after delimiting

I have a string input which looks like this var input = "AB-PQ-EF=CD-IJ=XY-JK". I want to know if there is a way using string.split() method in C# and LINQ such that I can get an array of strings which looks like this var output = ["AB-PQ", "PQ-EF",…
pango89
  • 265
  • 1
  • 3
  • 9
5
votes
3 answers

Split elements in array and add line break, then join - Javascript

I'm mapping through data in Reactjs. This JSX: {place.venue.location.formattedAddress} Is mapping through this Axios data request, specially, this array in my response: formattedAddress: Array(5) 0 : "Chester Rd" 1 : "London" 2 : "Greater London" 3…
Reena Verma
  • 1,617
  • 2
  • 20
  • 47
5
votes
1 answer

Splitting single data frame row into multiple rows while performing calculation

I have a df akin to df1 where I want to break out the rows so that the HOURS column is in intervals of 4, shown in df2. How would I approach this problem and what packages are recommended? IDs can have more than one sequence on a given day. For…
samuelt
  • 215
  • 1
  • 2
  • 10
5
votes
1 answer

split string and make key value pair

I have a following string in python: Date: 07/14/1995 Time: 11:31:50 Subject text: Something-cool I want to prepare a dict() from it with following key: [value] {"Date":["07/13/1995"], "Time": ["11:31:50"], "Subject text":["Something-cool"]} If I…
Anthony
  • 33,838
  • 42
  • 169
  • 278
5
votes
4 answers

Python: determine if three text strings stored in a dataframe have any words in common

Say I have the following dataframe df: A B C 0 mom;dad;son; sister;son; yes;no;maybe; 1 dad; daughter;niece; no;snow; 2 son;dad; cat;son;dad; tree;dad;son; 3 daughter;mom; niece; …
FaCoffee
  • 7,609
  • 28
  • 99
  • 174
5
votes
3 answers

How to split using a prefix character using regular expressions?

I would like to split the example string: ~Peter~Lois~Chris~Meg~Stewie on the character ~ and have the result be Peter Lois Chris Meg Stewie Using a standard string split function in javascript or C# the first result is of course an…
Craig
  • 770
  • 3
  • 14
  • 26
5
votes
1 answer

C# RegEx.Split delimiter followed by specific words

I am trying to split using Regex.Split strings like this one: string criteria = "NAME='Eduard O' Brian' COURSE='Math II' TEACHER = 'Chris Young' SCHEDULE='3' CAMPUS='C-1' "; We have the following 'reserved words': NAME, COURSE, TEACHER, SCHEDULE,…
Mercy
  • 75
  • 1
  • 7
5
votes
2 answers

xts split by week function specify first day of week as Sunday instead of default of Monday

Applying the split function to a xts object by weeks groups rows into weekly chunks. The default days in the group are Monday to Sunday. What do I do if I want the days in the group to be from Sunday to Saturday? library(xts) idx <-…
lessthanl0l
  • 1,035
  • 2
  • 12
  • 21
5
votes
3 answers

jq split string by a pattern

I have a json object with one of field having values for example "countries-sapi-1.0", "inventory-list-api-1.0-snapshot" Note that the first one has sapi and the other one has api. Using jq, how can i get countries-sapi or inventory-list-api I mean…
Naveen K Reddy
  • 429
  • 5
  • 13
5
votes
2 answers

Java split stream by predicate into stream of streams

I have hundreds of large (6GB) gziped log files that I'm reading using GZIPInputStreams that I wish to parse. Suppose each one has the format: Start of log entry 1 ...some log details ...some log details ...some log details Start of log…
Alexander
  • 59,041
  • 12
  • 98
  • 151
5
votes
2 answers

Sql remove duplicates from comma separated string

I want to make a query in sql-server which can make the following output as like column _B from column_A.Columns are varchar type. Column_A column_B karim,karim,rahim,masud,raju,raju …
Biddut
  • 418
  • 1
  • 6
  • 17
5
votes
5 answers

How to remove an element from a split String?

I'm trying to remove an element/item/entry from a split string. Let's say I got the string [string_] as follows: string string_ = "one;two;three;four;five;six"; Then I split this string to get each, let's say, item: string[] item =…
Bo. Ga.
  • 138
  • 1
  • 4
  • 12