Skip to content

Instantly share code, notes, and snippets.

@ju1ion
Created June 1, 2016 09:39
Show Gist options
  • Save ju1ion/95731feb7251d9cd1bd391982cd795bc to your computer and use it in GitHub Desktop.
Save ju1ion/95731feb7251d9cd1bd391982cd795bc to your computer and use it in GitHub Desktop.
C++ String split without boost
public:
static std::vector<std::string> splitStrA(const std::string &InputString, char delimiterChar) {
std::vector<std::string> ResultVec;
splitStrA(InputString, delimiterChar, ResultVec);
return ResultVec;
};
static std::vector<std::wstring> splitStrW(const std::wstring &InputString, wchar_t delimiterChar) {
std::vector<std::wstring> ResultVec;
splitStrW(InputString, delimiterChar, ResultVec);
return ResultVec;
};
#ifdef UNICODE
#define splitStr splitStrW
#else
#define splitStr splitStrA
#endif
private:
static std::vector<std::wstring> &splitStrW(const std::wstring &InputString, wchar_t delimiterChar, std::vector<std::wstring> &ResultVec) {
std::wstringstream sStream(InputString);
std::wstring item;
while (std::getline(sStream, item, delimiterChar)) {
ResultVec.push_back(item);
}
return ResultVec;
}
static std::vector<std::string> &splitStrA(const std::string &InputString, char delimiterChar, std::vector<std::string> &ResultVec) {
std::stringstream sStream(InputString);
std::string item;
while (std::getline(sStream, item, delimiterChar)) {
ResultVec.push_back(item);
}
return ResultVec;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment