c++、boost字符串操作

c++ STL+boost可以实现一些常用的字符串操作,记录如下

#include <iostream>
#include <string>
#include <boost/algorithm/string.hpp>
#include <boost/xpressive/xpressive_dynamic.hpp>

using namespace std;
using namespace boost;
using namespace boost::xpressive;
int main()
{
	//查找
	string data = "123456aaabbbccc\n123456aaabbbccc";
	list<string> str;
	auto ff = find_first(data, "123");
	auto fn = find_first(data, "10");
	cout << "ff: " << ff << endl << "fn: " << fn << endl;
	auto con = contains(data, "456");
	auto nocon = contains(data, "789");
	cout << "contains: " << con << endl;
	cout << "nocon: " << nocon << endl;
	auto i = find_all(str, data, "aaa");
	for (auto j : str)
		cout << j << endl;


	//替换
	string reData = "123456789";
	cout << "replace data: " << replace_all_copy(reData, "123", "") << endl;
	sregex reg = sregex::compile("\\d+");
	cout << "reg replace: " << regex_replace(reData, reg, "abc") << endl;

	//删除
	string delData = "123456789";
	cout << "del data: " << erase_all_copy(delData, "123") << endl;

	//分割
	string splitData = "123 456 789 asd fggaa gada";
	vector<string>spVec;
	split(spVec, splitData, is_any_of(" "));
	for (auto i : spVec)
		cout << "split data: " << i << endl;

	cin.get();
}

 

©️2020 CSDN 皮肤主题: 我行我“速” 设计师:Amelia_0503 返回首页