From 76b2d57f056a2d680f3317724e9c76fd0f4bc8bc Mon Sep 17 00:00:00 2001 From: Brett Date: Sun, 15 Oct 2023 16:43:20 -0400 Subject: [PATCH] add split for char --- include/blt/std/string.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/blt/std/string.h b/include/blt/std/string.h index 6a6e476..8a6935a 100755 --- a/include/blt/std/string.h +++ b/include/blt/std/string.h @@ -170,6 +170,20 @@ namespace blt::string return tokens; } + static inline std::vector split(std::string s, char delim) + { + size_t pos = 0; + std::vector tokens; + while ((pos = s.find(delim)) != std::string::npos) + { + auto token = s.substr(0, pos); + tokens.push_back(token); + s.erase(0, pos + 1); + } + tokens.push_back(s); + return tokens; + } + // https://stackoverflow.com/questions/3418231/replace-part-of-a-string-with-another-string static inline bool replace(std::string& str, const std::string& from, const std::string& to) {