boost——string_algo字符串的操作(一)

#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 :根据字典顺序检测一个字符串是否小于另一个字符串


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值