mirror of
https://github.com/jslightham/cpp-utils.git
synced 2026-03-09 18:12:26 +01:00
Initial commit
This commit is contained in:
20
String.h
Normal file
20
String.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef STRING_H
|
||||
#define STRING_H
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// Split a string on a delimiter to a vector of strings
|
||||
inline std::vector<std::string> split(const std::string &str, const char delimiter) {
|
||||
std::vector<std::string> result;
|
||||
std::stringstream ss(str);
|
||||
std::string token;
|
||||
|
||||
while (std::getline(ss, token, delimiter)) {
|
||||
result.push_back(token);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif //STRING_H
|
||||
Reference in New Issue
Block a user