All Questions

2405
votes
72answers
1822773 views

The most elegant way to iterate the words of a string

What is the most elegant way to iterate the words of a string? The string can be assumed to be composed of words separated by whitespace. Note that I'm not interested in C string functions or that ki...
1293
votes
52answers
496637 views

How do you split a list into evenly sized chunks?

I have a list of arbitrary length, and I need to split it up into equal size chunks and operate on it. There are some obvious ways to do this, like keeping a counter and two lists, and when the second...
417
votes
36answers
715860 views

How do I split a string so I can access item x?

Using SQL Server 2005, how do I split a string so I can access item x? For example Take a string "Hello John Smith". How can I split the string by space and access the item at index 1 which should r...
354
votes
33answers
449077 views

How do I tokenize a string in C++?

Java has a convenient split method: String str = "The quick brown fox"; String[] results = str.split(" "); Is there an easy way to do this in C++?
40
votes
4answers
14969 views

Split comma-separated 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 ...
133
votes
10answers
244733 views

Turning a Comma Separated string into individual rows

I have a SQL Table like this: | SomeID | OtherID | Data +----------------+-------------+------------------- | abcdef-..... | cdef123-... | 18,20,22 | abcdef-..... | 4554a24-... | 17,1...
109
votes
13answers
140208 views

Split a column of a data frame to multiple columns

I'd like to take data of the form before = data.frame(attr = c(1,30,4,6), type=c('foo_and_bar','foo_and_bar_2')) attr type 1 1 foo_and_bar 2 30 foo_and_bar_2 3 4 foo_and_bar 4 ...
239
votes
33answers
240125 views

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)...
69
votes
21answers
221306 views

T-SQL split string

I have a SQL Server 2008 R2 column containing a string which I need to split by a comma. I have seen many answers on StackOverflow but none of them works in R2. I have made sure I have select permissi...
386
votes
10answers
588852 views

How do I split a string, breaking at a particular character?

I have this string 'john smith~123 Street~Apt 4~New York~NY~12345' Using JavaScript, what is the fastest way to parse this into var name = "john smith"; var street= "123 Street"; //etc...

Previous Next