fork(1) 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_LastFoundDelimeterPos = 0;
  12.  
  13. // First find not delimeter character after last found delimeter position
  14. while ((x_StartOfCurrentSubstring = vrx_String.find_first_not_of(vc_Delimeter, x_LastFoundDelimeterPos)) != std::string::npos)
  15. {
  16. x_LastFoundDelimeterPos = vrx_String.find(vc_Delimeter, x_StartOfCurrentSubstring);
  17. if (x_LastFoundDelimeterPos != std::string::npos)
  18. {
  19. x_Result.push_back(vrx_String.substr(x_StartOfCurrentSubstring, x_LastFoundDelimeterPos - x_StartOfCurrentSubstring));
  20. }
  21. else
  22. {
  23. x_Result.push_back(vrx_String.substr(x_StartOfCurrentSubstring));
  24. }
  25. }
  26.  
  27. return x_Result;
  28. };
  29.  
  30. std::vector<std::string> result = fn_Tokenize("A;B,.dgsklgasg;C;DEF", ';');
  31.  
  32. for (std::string a : result)
  33. {
  34. std::cout << a << std::endl;
  35. }
  36.  
  37. // your code goes here
  38. return 0;
  39. }
Success #stdin #stdout 0s 5296KB
stdin
Standard input is empty
stdout
A
B,.dgsklgasg
C
DEF