Advertisement
STANAANDREY

std::string split

Jun 24th, 2020
1,571
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. vector<string> strSplit(string s, string sep)
  5. {
  6.     const size_t n = s.size();
  7.     vector<string> splited;
  8.     int st = 0, fin = n - 1;
  9.     for (size_t i = 0; i <= n; i++)
  10.     {
  11.         if (sep.find(s[i]) != string::npos || i == n)
  12.         {
  13.             fin = i;
  14.             string temp = string(s.begin() + st, s.begin() + fin);
  15.             if (!temp.empty())
  16.                 splited.push_back(temp);
  17.             st = i + 1;
  18.         }
  19.     }
  20.     return splited;
  21. }
  22.  
  23. int main()
  24. {
  25.     vector<string> v = strSplit(" lol     asd;;;;;;;;;;;;;0,.;fgh,,,.", ";  .,");
  26.     for (auto it : v)
  27.         cerr << it << endl;
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement