Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ Programming ➜ STL ➜ Explode function for strings

Explode function for strings

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Greven   Canada  (835 posts)  Bio
Date Tue 07 Jun 2005 07:12 AM (UTC)
Message
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.

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
Top

Posted by Flannel   USA  (1,230 posts)  Bio
Date Reply #1 on Tue 07 Jun 2005 08:00 AM (UTC)
Message
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:
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 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).

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
Top

Posted by Dralnu   USA  (277 posts)  Bio
Date Reply #2 on Tue 07 Jun 2005 05:26 PM (UTC)
Message
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++...
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


22,001 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.