Monday, June 27, 2016

Trim function for std::string

std::string stdtrim(std::string& str)
{
    size_t first = str.find_first_not_of(' ');
    size_t last = str.find_last_not_of(' ');
    return (std::string::npos == first) || (std::string::npos == last) ? "" : str.substr(first, (last - first + 1));
}

No comments:

Post a Comment