-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathstring_trim(strip)_boost.cpp
27 lines (24 loc) · 1.08 KB
/
string_trim(strip)_boost.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <boost/algorithm/string/trim.hpp>
#include <boost/algorithm/string/trim_all.hpp>
#include <iostream>
//https://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-stdstring
//https://blog.csdn.net/zhangxiong1985/article/details/84453292
int main(){
std::string str(" hello world! ");
std::cout << "original: '" << str << "'" << std::endl;
std::cout << "trimed from right: '" << boost::trim_right_copy(str) << "'" << std::endl;
std::cout << "trimed from left: '" << boost::trim_left_copy(str) << "'" << std::endl;
std::cout << "trimed from left and right: '" << boost::trim_all_copy(str) << "'" << std::endl;
boost::trim_right(str);
std::cout << "trimed from right(in-place): '" << str << "'" << std::endl;
boost::trim_left(str);
std::cout << "trimed from left(in-place): '" << str << "'" << std::endl;
}
/*
original: ' hello world! '
trimed from right: ' hello world!'
trimed from left: 'hello world! '
trimed from left and right: 'hello world!'
trimed from right(in-place): ' hello world!'
trimed from left(in-place): 'hello world!'
*/