Dreikblack Posted February 8 Share Posted February 8 1. If after delimiter 1 symbol in result will be empty string 2. Empty string is not shown if delimiter was last symbol. Could be optionable with bool param if intended #include "UltraEngine.h" using namespace UltraEngine; int main(int argc, const char* argv[]) { WString s = "\n1"; vector<WString> sarr = s.Split("\n"); for (auto s : sarr) { if (s.empty()) { Print("Empty"); } else { Print(s); } } Print("2nd case:"); s = "11\n"; sarr = s.Split("\n"); for (auto s : sarr) { if (s.empty()) { Print("Empty"); } else { Print(s); } } return 0; } 1 Quote Link to comment Share on other sites More sharing options...
Dreikblack Posted February 8 Author Share Posted February 8 Made own function for now: #include "UltraEngine.h" using namespace UltraEngine; static vector<WString> Split(WString const& text, WString const& delimiter) { WString tempText = text; vector<WString> result; while (!tempText.empty()) { int delimiterIndex = tempText.Find(delimiter); if (delimiterIndex == -1) { result.push_back(tempText); break; } result.push_back(tempText.Left(delimiterIndex)); tempText = tempText.Right((int)tempText.length() - delimiterIndex - (int)delimiter.length()); if (tempText.empty() && delimiterIndex != -1) { result.push_back(""); } } return result; } static void PrintArr(vector<WString> sarr) { for (auto s : sarr) { if (s.empty()) { Print("Empty"); } else { Print(s); } } } int main(int argc, const char* argv[]) { PrintArr(Split("\n1", "\n")); Print(" "); PrintArr(Split("1\n", "\n")); Print(" "); PrintArr(Split("\n1\n", "\n")); Print(" "); PrintArr(Split("1\n1\n", "\n")); return 0; } Quote Link to comment Share on other sites More sharing options...
Solution Josh Posted Tuesday at 09:25 PM Solution Share Posted Tuesday at 09:25 PM I am a little bit wary of modifying the way this works, but we can try it. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.