User Tools

Site Tools


c:string:trim
no way to compare when less than two revisions

Differences

This shows you the differences between two versions of the page.


Last revision
c:string:trim [2019/11/14 23:23] – created odefta
Line 1: Line 1:
 +====== Trim a std::string ======
 +
 +<code cpp>
 +std::string& ltrim(std::string& str, const std::string& chars = "\t\n\v\f\r ")
 +{
 + str.erase(0, str.find_first_not_of(chars));
 + return str;
 +}
 +
 +std::string& rtrim(std::string& str, const std::string& chars = "\t\n\v\f\r ")
 +{
 + str.erase(str.find_last_not_of(chars) + 1);
 + return str;
 +}
 +
 +std::string& trim(std::string& str, const std::string& chars = "\t\n\v\f\r ")
 +{
 + return ltrim(rtrim(str, chars), chars);
 +}
 +</code>
  
c/string/trim.txt · Last modified: 2023/07/04 19:36 by 127.0.0.1