VTK读取 replace_all字符串整理 regex_match关键词匹配

8 篇文章 0 订阅
```cpp

```cpp
#include <iostream>
using namespace std;
#include<stdio.h>
#include<stdlib.h>
#include <time.h>
#include<iostream>
#include<string>
#include<fstream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
#include<unordered_set>
#include<unordered_map>
#include <regex> 

string replace_all(string str, char ini, char goal)
{
	string str_ = str;
	for (auto &e : str_)
		if (e == ini)
			e = goal;
	return str_;
}
string replace_all(string &str, string ini, string goal)
{
	string str_ = str;
	while (str_.find(ini) != -1)
		str_ = str_.replace(str_.find("ini"), ini.size(), goal);//将line中的第一个&替换成1 
	return str_;
}



string erase_all_char(string str, char ch)
{
	string str0 = str;
	int pos = 0;
	int size = str0.size();
	for (int i = 0; i < size; i++)
	{
		if (str0[i] == ch)
		{
			str0.erase(str0.find(ch), 1);
			i--;
			size = str0.size();
		}
	}
	return str0;
}

string erase_all_str(string str, string str_goal)
{
	string str_ = str;
	int size = str_goal.size();
	while (str_.find(str_goal) != -1)
		str_.erase(str_.find(str_goal), size);//将line中的第一个&替换成1 
	return str_;
}

int clear_useless_char(string &fields)
{
	replace_all(fields, "\n", " ");
	replace_all(fields, "\r", " ");
	replace_all(fields, "\t", " ");

	fields.erase(fields.find_last_not_of(' ') + 1);
	return 0;
}



void replace_all_(string str_, char ini, char goal)
{
	for (auto &e : str_)
		if (e == ini)
			e = goal;
}
void replace_all_(string &str_, string ini, string goal)
{
	while (str_.find(ini) != -1)
		str_ = str_.replace(str_.find("ini"), ini.size(), goal);//将line中的第一个&替换成1
}


void erase_all_char_(string &str0,char ch)
{
	int pos = 0;
	int size = str0.size();
	for (int i = 0; i < size; i++)
	{
		if (str0[i] == ch)
		{
			str0.erase(str0.find(ch), 1);
			i--;
			size = str0.size();
		}
	}
}

void erase_all_str_(string str_, string str_goal)
{
	int size = str_goal.size();
	while (str_.find(str_goal) != -1)
		str_.erase(str_.find(str_goal), size);//将line中的第一个&替换成1
}

int main()
{
	string str5 = "my ,ini dream is, have my ini girlfriend,which is ini love";
	string str_goal = "ini";
	string str50 = erase_all_str(str5, str_goal);
	string str_test = "abcdefg";
	int pos = str_test.find("de");

	string str = "my ini dream is have my ini girlfriend,which is ini love";
	string ini = "ini";
	string goal = "last";
	string str1 = replace_all(str, ini, goal);

	string str0 = "my ,ini dream is, have my ini girlfriend,which is ini love";
	char ini0 = ',';
	char  goal0 = ' ';
	string str2 = replace_all(str0, ini0, goal0);

	string line = "  SCALARS  ,Displacement , float 3   ";
	while (line[0] == ' ')
		line.erase(0, 1);

	string line0 = replace_all(line, ',', ' ');
	clear_useless_char(line0);

	line0 = erase_all_char(line0, ' ');


	string line2 = "  SCALARS Displacement float 3  ";
	erase_all_char_(line2, ',');
	clear_useless_char(line2);
	erase_all_char_(line2, ' ');


	//regex elementTypePattern("ELEMENTTYPE=(.*)ELSET=(.*)");
	regex displacementPattern("SCALARS(.*)float(.*)");
	std::smatch results;

	string All;
	string type;
	string num;
	if (regex_match(line2, results, displacementPattern))
	{
		All = results[0];
		type= results[1];
		num = results[2];
	}
	



	//stringstream 






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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值