diff --git a/Algorithms.hpp b/Algorithms.hpp index 38090f0..7296aff 100644 --- a/Algorithms.hpp +++ b/Algorithms.hpp @@ -517,6 +517,29 @@ int findNumOccurrence(std::string str, char ch){ return num; } +//Return a vector of strings split on the delimiter +std::vector split(std::string str, char delimiter){ + std::vector splitStrings; + int location = 0; + location = str.find(delimiter); + while(location != std::string::npos){ + //Split the string + std::string firstString = str.substr(0, location); + str = str.substr(location + 1); //+1 to skip the delimiter itself + //Add the string to the vector + splitStrings.push_back(firstString); + //Get the location of the next delimiter + location = str.find(delimiter); + } + //Get the final string if it isn't empty + if(!str.empty()){ + splitStrings.push_back(str); + } + //Return the vector of strings + return splitStrings; +} + + }