Guest User

Untitled

a guest
Nov 17th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. int split( const std::string & srcStr, std::vector<std::string> & destArray, const std::string & delimiter ){
  2. if( srcStr.empty() ){
  3. return 0;
  4. }
  5. std::string::size_type startPos = srcStr.find_first_not_of( delimiter );
  6. size_t lengthOfDelimiter = delimiter.length();
  7. while( std::string::npos != startPos ){
  8. std::string::size_type nextPos = srcStr.find( delimiter, startPos );
  9. std::string str;
  10. if( std::string::npos != nextPos ){
  11. str = srcStr.substr( startPos, nextPos - startPos );
  12. nextPos += lengthOfDelimiter;
  13. }
  14. else{
  15. str = srcStr.substr( startPos );
  16. }
  17. startPos = nextPos;
  18. if( !str.empty() ){
  19. destArray.push_back( str );
  20. }
  21. }
  22. return destArray.size();
  23. }
Add Comment
Please, Sign In to add comment