#include <boost/algorithm/string.hpp>
using namespace boost;
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string str("readme.txt") ;
if (ends_with(str, "txt"))
{
cout << to_upper_copy (str) + " UPPER" << endl ;
assert(ends_with(str, "txt")) ;
}
replace_first(str,"readme", "followme") ;
cout << str << endl ;
vector<char> v (str.begin(),str.end()) ;
vector<char> v2 = to_upper_copy(erase_first_copy(v,"txt")) ;
for (int i=0; i<v2.size(); ++i)
{
cout << v2[i] ;
}
cout << "------------------------------------------------------" << endl;
string str2("I don't know");
cout << to_upper_copy(str2) << endl ;
cout << str2 << endl;
to_upper(str2) ;
cout << str2 << endl ;
cout <<"-------------------------------------------------------" << endl;
string str3("Power Bomb") ;
assert(iends_with(str3, "bomb")) ;
assert(!ends_with(str3, "bomb")) ;
assert(istarts_with(str3, "Power")) ;
assert(contains(str3, "er")) ;
string str4 = to_lower_copy(str3) ;
assert(iequals(str4,str3)) ;
string str5 = "Power Suit" ;
assert(ilexicographical_compare(str3, str5)) ;//忽略大小写按字典顺序比较
assert(all(str4.substr(0,5), is_lower())) ;
}
命名规则:
前缀 i :有此前缀,大小写不敏感,反之大小写敏感
后缀_copy :有此后缀,返回一个拷贝,否则在原字符串中处理
后缀_if :有此后缀,需要一个作为判断式的微词函数对象,否者使用默认标准
大小写转换:
to_lower 、to_upper 两组
判断式:
start_with : 检测一个字符串是否为另一个字符串的前缀
end_with : 检测一个字符串是否为另一个字符串的后缀
contains : 检测一个字符串是否被另一个字符串包含
equals : 检测两个字符串是否相等
all : 检测一个字符串中的所有字符时候满足指定的判断式
lexicographical_compare :根据字典顺序检测一个字符串是否小于另一个字符串