Echo89

C++ Explode function.

Nov 28th, 2012
61
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. vector<string> explode(string str, string del)
  2. {
  3.     int slen = str.length();
  4.     int dlen = del.length();
  5.     vector<string> r;
  6.     vector<string> f (0);
  7.     if(dlen == 0) return f;
  8.     if(slen == 0) return f;
  9.     while(str.find(del) != string::npos)
  10.     {
  11.         r.push_back(str.substr(0, str.find(del)));
  12.         str.erase(0, str.find(del) + dlen);
  13.     }
  14.     if(str.length() > 0)
  15.     {
  16.         r.push_back(str);
  17.         str.erase(0, str.length());
  18.     }
  19.  
  20.     return r;
  21. }
RAW Paste Data