fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. int main() {
  7. auto fn_Tokenize = [](const std::string& vrx_String, const char vc_Delimeter) -> std::vector<std::string>
  8. {
  9. std::vector<std::string> x_Result;
  10. size_t x_StartOfCurrentSubstring = 0;
  11. size_t x_CurrentDelimeterPos = 0;
  12.  
  13. // First find not delimeter character after last found delimeter position
  14. for(;;)
  15. {
  16. x_CurrentDelimeterPos = vrx_String.find_first_of(vc_Delimeter, x_CurrentDelimeterPos);
  17.  
  18. if (x_CurrentDelimeterPos != std::string::npos)
  19. {
  20. x_Result.push_back(vrx_String.substr(x_StartOfCurrentSubstring, x_CurrentDelimeterPos - x_StartOfCurrentSubstring));
  21. ++x_CurrentDelimeterPos;
  22. x_StartOfCurrentSubstring = x_CurrentDelimeterPos;
  23. }
  24. else
  25. {
  26. x_Result.push_back(vrx_String.substr(x_StartOfCurrentSubstring));
  27. break;
  28. }
  29. }
  30.  
  31. return x_Result;
  32. };
  33.  
  34. std::vector<std::string> result = fn_Tokenize("A;B;;;C;DEF", ';');
  35.  
  36. for (std::string a : result)
  37. {
  38. std::cout << a << std::endl;
  39. }
  40.  
  41. // your code goes here
  42. return 0;
  43. }
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
A
B


C
DEF