//
// Created by 13989 on 2022/10/26.
//
#include <iostream>
#include <fstream>
#include <istream>
#include <sstream>
#include <string>
#include "string_util.h"
using namespace std;
void test()
{
string file1 = "D:\\myProject\\k0.log";
ifstream ifile;
ifile.open(file1, ios::in);
if (!ifile.is_open()) {
return;
}
string str;
while (getline(ifile, str)) {
cout << str << endl;
vector<string> res;
StringSplit(str, '(', res);
for (int i = 1; i < res.size(); i++) {
res[i].replace(res[i].find(')'), 1, "");
}
for (auto s : res) {
cout << s << endl;
}
}
ifile.close();
}
void StringSplit(std::string str, char cha, std::vector<std::string>& res)
{
istringstream iss(str);
string token;
while (getline(iss, token, cha)) {
// cout << token << endl;
res.push_back(token);
}
}
void StringReplace(std::string& str, char x, const string y)
{
str.replace(str.find(x), 1, y);
}
C++字符串处理
最新推荐文章于 2024-03-24 23:46:23 发布