Is there an equivalent in C++ of PHP’s explode() function? [duplicate]

Here’s a simple example implementation: #include <string> #include <vector> #include <sstream> #include <utility> std::vector<std::string> explode(std::string const & s, char delim) { std::vector<std::string> result; std::istringstream iss(s); for (std::string token; std::getline(iss, token, delim); ) { result.push_back(std::move(token)); } return result; } Usage: auto v = explode(“hello world foo bar”, ‘ ‘); Note: @Jerry’s idea of writing to an … Read more

Split a string with two delimiters into two arrays (explode twice)

You can explode the string by commas, and then explode each of those values by x, inserting the result values from that into the two arrays: $str = “20×9999,24×65,40×5”; $array1 = array(); $array2 = array(); foreach (explode(‘,’, $str) as $key => $xy) { list($array1[$key], $array2[$key]) = explode(‘x’, $xy); } Alternatively, you can use preg_match_all, matching … Read more

Explode a paragraph into sentences in PHP

You can use preg_split() combined with a PCRE lookahead condition to split the string after each occurance of ., ;, :, ?, !, .. while keeping the actual punctuation intact: Code: $subject=”abc sdfs. def ghi; this is [email protected]! asdasdasd? abc xyz”; // split on whitespace between sentences preceded by a punctuation mark $result = preg_split(‘/(?<=[.?!;:])\s+/’, … Read more

Hive Explode / Lateral View multiple arrays

I found a very good solution to this problem without using any UDF, posexplode is a very good solution : SELECT COOKIE , ePRODUCT_ID, eCAT_ID, eQTY FROM TABLE LATERAL VIEW posexplode(PRODUCT_ID) ePRODUCT_IDAS seqp, ePRODUCT_ID LATERAL VIEW posexplode(CAT_ID) eCAT_ID AS seqc, eCAT_ID LATERAL VIEW posexplode(QTY) eQTY AS seqq, eDateReported WHERE seqp = seqc AND seqc = … Read more