C++ 字符串去除两端空格

 

C++ 字符串去除两端空格trim()经常用到。这里记录一下,方便自己使用。

//C++ 去字符串两边的空格
void trim(string &s) 
{
    if (s.empty()) 
    {
        return ;
    }
    s.erase(0,s.find_first_not_of(" "));
    s.erase(s.find_last_not_of(" ") + 1);
}

 

posted @ 2020-09-02 09:18  He_LiangLiang  阅读(3761)  评论(0编辑  收藏  举报