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