trim_example.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Boost string_algo library example file ---------------------------------//
  2. // Copyright Pavol Droba 2002-2003. Use, modification and
  3. // distribution is subject to the Boost Software License, Version
  4. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. // See http://www.boost.org for updates, documentation, and revision history.
  7. #include <string>
  8. #include <iostream>
  9. #include <boost/algorithm/string/trim.hpp>
  10. #include <boost/algorithm/string/classification.hpp>
  11. using namespace std;
  12. using namespace boost;
  13. int main()
  14. {
  15. cout << "* Trim Example *" << endl << endl;
  16. string str1(" 1x x x x1 ");
  17. string str2("<>trim<>");
  18. string str3("123abs343");
  19. // Simple left trim
  20. cout << "trim_left copy of str1: " << "\"" << trim_left_copy( str1 ) << "\"" << endl;
  21. // Inplace right trim
  22. trim_right( str1 );
  23. cout << "trim_right on str1: " << "\"" << str1 << "\"" << endl;
  24. // Parametric trim. 'Space' is defined using is_any_of predicate
  25. cout
  26. << "trimmed copy of str4 ( space='<>' ): "
  27. << "\""<< trim_copy_if( str2, is_any_of("<>") ) << "\"" << endl;
  28. // Parametric trim. 'Space' is defined using is_digit predicate
  29. cout
  30. << "trimmed copy of str5 ( space=digit ): "
  31. << "\"" << trim_copy_if( str3, is_digit() ) << "\"" << endl;
  32. cout << endl;
  33. return 0;
  34. }