/***********write by myself***********/
/***********begin test file***********/
#include <iostream>
#include <string>

int main()
{
 std::string str1 = "   hello world!   ";
 std::string trimstring = " ";
 std::cout << "str = \"" << str1 << "\"" << std::endl;
 std::cout << "str.find_first_of(' ')     : " << str1.find_first_of(trimstring)     << std::endl;
 std::cout << "str.find_first_not_of(' ') : " << str1.find_first_not_of(trimstring) << std::endl;
 std::cout << "str.find_last_of(' ')     : " << str1.find_last_of(trimstring)      << std::endl;
 std::cout << "str.find_last_not_of(' ')  : " << str1.find_last_not_of(trimstring)  << std::endl;
 str1.erase(str1.find_last_not_of(trimstring)+1);
 std::cout << "after right trim : \"" << str1 << "\"" << std::endl;
 str1.erase(0,str1.find_first_not_of(trimstring));
 std::cout << "after left trim  : \"" << str1 << "\"" << std::endl;
 return 0;
}
/***********end test file***********/

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-10
  • 2022-12-23
  • 2022-01-23
  • 2022-12-23
  • 2022-02-19
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-09
  • 2021-09-14
  • 2022-12-23
  • 2021-10-25
  • 2022-12-23
相关资源
相似解决方案