explode funktion wie in php
-
Hallo kann mir jemand eine explodefunktion wie in php schreiben oder kennt jemand eine?
-
Am besten schaust du dir die Stringfunktionen an ( http://cppreference.com/cppstring/index.html ) oder versuchst boost::regex.
Hier mal ein kleines Beispiel:#include <iostream> #include <string> using namespace std; void ExplodeString(const string& both, string& front, string& back, const char separator = '|') { const string::size_type pos = both.find_first_of(separator); if(pos == string::npos) { front = both; } else { front = both.substr(0,pos); back = both.substr(pos+1); } } int main() { const string test("Hallo|Welt!"); string t1, t2; ExplodeString(test, t1, t2); std::cout << test << std::endl << t1 << std::endl << t2 << std::endl; }mfg.
-