SHARE
TWEET

Untitled

a guest Oct 21st, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. std::vector<std::string> split(const std::string& s, char delimiter = ';'){
  2.     std::vector<std::string> result;
  3.     std::string tmp = s;
  4.  
  5.     while(tmp.find(delimiter) != std::string::npos)
  6.     {
  7.         std::string new_part = tmp.substr(0, tmp.find(delimiter));
  8.         tmp = tmp.substr(tmp.find(delimiter)+1, tmp.size());
  9.         if(not (new_part.empty()))
  10.         {
  11.             if(new_part.front()=='"'){
  12.                 std::string old_part;
  13.                 old_part = new_part;
  14.             }else if(new_part.back()=='"'){
  15.                 final = old_part + " " + new_part;
  16.                 result.push_back(final.sbstr(1, final.size()-2));                
  17.             }else{
  18.                 result.push_back(new_part);
  19.             }
  20.         }
  21.     }
  22.     if(not tmp.empty())
  23.     {
  24.         if(tmp.front()=='"'){
  25.             std::string old_part;
  26.             old_part = tmp;
  27.         }else if(tmp.back()=='"'){
  28.             final = old_part + " " + tmp;
  29.             result.push_back(final.sbstr(1, final.size()-2));                
  30.         }else{
  31.             result.push_back(tmp);
  32.         }
  33.     }
  34.     return result;
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top