日常开发中经常需要通过某种格式将一个字符串拆分成多个字符串,以下是一种实现:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
//通过字符进行拆分
void strSplit(const string& str, const char split, vector<string>& res)
{
if(str == "")
{
return;
}
string&& strs = str + split;
size_t pos = strs.find(split);
while(pos != string::npos)
{
res.emplace_back(strs.substr(0, pos));
strs = move(strs.substr(pos + 1, strs.size()));
pos = strs.find(split);
}
}
//通过字符串进行拆分
void strSplit(const string& str, const string& splits, vector<string>& res)
{
if(str == "")
{
return;
}
string&& strs = str + splits;
size_t pos = strs.find(splits);
int splitsLength = splits.size();
while (pos !=