c++删除字符串中所有换行和空格

static inline void StringTrans(std::string& s)
{
 // 删除所有换行
 std::string::size_type r = s.find('\r\n');
 while (r != std::string::npos)
 {
  if (r != std::string::npos)
  {
   s.replace(r, 1, "");
   r = s.find('\r\n');
  }
 }

 //删除所有空格
 s.erase(std::remove(s.begin(), s.end(), ' '), s.end());
}

猜你喜欢

转载自blog.csdn.net/www_dong/article/details/129697792