join()

Data / String Functions

Description

Combines a vector of strings into one string using a separator.

Syntax

std::string join(std::vector<std::string> v, std::string sep)

Parameters

NameTypeDescription
vstd::vectorthe strings to join
sepstd::stringseparator string

Returns

std::string

Related

Under the Hood

From Processing.h:

inline std::string join(const std::vector<std::string>& v, const std::string& sep) { std::string o; for (size_t i=0; i<v.size(); i++) { if(i) o+=sep; o+=v[i]; } return o; } static String join(const std::string& delim, std::initializer_list<std::string> parts) { String result; bool first = true; for (const auto& p : parts) { if (!first) result += delim; result += p; first = false; } return result; } template<typename Container> static String join(const std::string& delim, const Container& parts) { String result; bool first = true; for (const auto& p : parts) { if (!first) result += delim; result += p; first = false; } return result; } std::string join(const std::string& separator) const { if (data.empty()) return ""; std::string r = std::to_string(data[0]); for (size_t i = 1; i < data.size(); i++) { r += separator; r += std::to_string(data[i]); } return r; } std::string join(const std::string& separator) const { if (data.empty()) return ""; std::string r = data[0]; for (size_t i = 1; i < data.size(); i++) { r += separator; r += data[i]; } return r; } static std::string join(const std::vector<std::string>& v, const std::string& sep);

Under the Hood

From Processing.cpp:

std::string PApplet::join(const std::vector<std::string>& v, const std::string& sep) { std::string r; for (size_t i=0;i<v.size();i++){if(i)r+=sep;r+=v[i];} return r; }