trim()
Data / String FunctionsDescription
Removes whitespace characters from the beginning and end of a string.
Syntax
std::string trim(std::string s)
Parameters
| Name | Type | Description |
|---|---|---|
| s | std::string | string to trim |
Returns
std::stringRelated
Under the Hood
From Processing.h:
inline std::string trim(const std::string& s) {
size_t a=s.find_first_not_of(" \t\n\r"), b=s.find_last_not_of(" \t\n\r");
return a==std::string::npos ? "" : s.substr(a, b-a+1);
}
String trim() const {
size_t start = find_first_not_of(" \t\n\r\f\v");
if (start == npos) return String("");
size_t end = find_last_not_of(" \t\n\r\f\v");
return String(substr(start, end - start + 1));
}
static std::string trim(const std::string& s);
Under the Hood
From Processing.cpp:
std::string PApplet::trim(const std::string& s) {
size_t a=s.find_first_not_of(" \t\n\r"), b=s.find_last_not_of(" \t\n\r");
return a==std::string::npos?"":s.substr(a,b-a+1);
}