Splits up a string using a delimiter
| 36 | |
| 37 | // Splits up a string using a delimiter |
| 38 | inline void Split(const std::wstring& str, std::vector<std::wstring>& parts, const std::wstring& delimiters = L" ") |
| 39 | { |
| 40 | // Skip delimiters at beginning |
| 41 | std::wstring::size_type lastPos = str.find_first_not_of(delimiters, 0); |
| 42 | |
| 43 | // Find first "non-delimiter" |
| 44 | std::wstring::size_type pos = str.find_first_of(delimiters, lastPos); |
| 45 | |
| 46 | while (std::wstring::npos != pos || std::wstring::npos != lastPos) |
| 47 | { |
| 48 | // Found a token, add it to the vector |
| 49 | parts.push_back(str.substr(lastPos, pos - lastPos)); |
| 50 | |
| 51 | // Skip delimiters. Note the "not_of" |
| 52 | lastPos = str.find_first_not_of(delimiters, pos); |
| 53 | |
| 54 | // Find next "non-delimiter" |
| 55 | pos = str.find_first_of(delimiters, lastPos); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | // Splits up a string using a delimiter |
| 60 | inline std::vector<std::wstring> Split(const std::wstring& str, const std::wstring& delimiters = L" ") |