split()
Data / String FunctionsDescription
Splits a string into substrings using a delimiter character.
Syntax
std::vector<std::string> split(std::string s, char d)
Parameters
| Name | Type | Description |
|---|---|---|
| s | std::string | the string to split |
| d | char | delimiter character |
Returns
std::vectorRelated
Under the Hood
From Processing.h:
inline std::vector<std::string> split(const std::string& s, char d) {
std::vector<std::string> o; std::stringstream ss(s); std::string t;
while (std::getline(ss, t, d)) o.push_back(t);
return o;
}
std::vector<String> split(const std::string& delim) const {
std::vector<String> result;
if (delim.empty()) {
result.push_back(String(*this));
return result;
}
size_t start = 0, pos;
while ((pos = find(delim, start)) != npos) {
result.push_back(String(substr(start, pos - start)));
start = pos + delim.size();
}
result.push_back(String(substr(start)));
return result;
}
static std::vector<std::string> split(const std::string& s, char d);
Under the Hood
From Processing.cpp:
std::vector<std::string> PApplet::split(const std::string& s, char delim) {
std::vector<std::string> r; std::string t;
for (char c : s) { if (c==delim){r.push_back(t);t.clear();}else t+=c; }
r.push_back(t); return r;
}