Split comma-separated strings in a column into separate rows

Several alternatives: 1) two ways with data.table: library(data.table) # method 1 (preferred) setDT(v)[, lapply(.SD, function(x) unlist(tstrsplit(x, “,”, fixed=TRUE))), by = AB ][!is.na(director)] # method 2 setDT(v)[, strsplit(as.character(director), “,”, fixed=TRUE), by = .(AB, director) ][,.(director = V1, AB)] 2) a dplyr / tidyr combination: library(dplyr) library(tidyr) v %>% mutate(director = strsplit(as.character(director), “,”)) %>% unnest(director) 3) with … Read more

How to split a string in Java

Just use the appropriate method: String#split(). String string = “004-034556”; String[] parts = string.split(“-“); String part1 = parts[0]; // 004 String part2 = parts[1]; // 034556 Note that this takes a regular expression, so remember to escape special characters if necessary. there are 12 characters with special meanings: the backslash \, the caret ^, the … Read more

How do I iterate over the words of a string?

I use this to split string by a delimiter. The first puts the results in a pre-constructed vector, the second returns a new vector. #include <string> #include <sstream> #include <vector> #include <iterator> template <typename Out> void split(const std::string &s, char delim, Out result) { std::istringstream iss(s); std::string item; while (std::getline(iss, item, delim)) { *result++ = … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)