After using php for a while and coming back to c++, I find myself missing the explode function a great deal, along with the corresponding implode function. Does anyone know if the string class in c++ has the equivalent? I googled for a while but couldn't find any document for explode. Or perhaps someone has written one themselves? If anyone has any information it would be greatly appreciated.
Explode function for strings
Posted by Greven on Tue 07 Jun 2005 07:12 AM — 3 posts, 26,893 views.
There's a good deal of them out there, search for tokenize, not explode.
Actually, just for kicks I searched for C++ explode, and the first link was:
http://www.emuboards.com/invision/lofiversion/index.php/t19541.html
which contains:
If that doesn't work as you'd like it, try looking through the results for C++ tokenize, as that's what it'll be called (because of C).
Actually, just for kicks I searched for C++ explode, and the first link was:
http://www.emuboards.com/invision/lofiversion/index.php/t19541.html
which contains:
vector<string> explode(string s, string e) {
vector<string> ret;
int iPos = s.find(e, 0);
int iPit = e.length();
while(iPos>-1) {
if(iPos!=0)
ret.push_back(s.substr(0,iPos));
s.erase(0,iPos+iPit); // poistetaan stringistä ylimääräiset scheißet
iPos = s.find(e, 0); // haetaan erottimen sijainti
} // end while
if(s!="")
ret.push_back(s);
return ret;
}
If you can get a good compiler that can handle it, I think you can use two codebasesin making a program. If nothing else works, you might could try mixing PHP and C++...