字符串拆分的实现(希望能帮到你)

void spit_string(map<int,std::string>& data,string src_data,string sign)
{
int label = 0;
int label_next = 0;
int label_p =0;
int num = 0;
//
string str_temp;
label = src_data.find(sign,0);




if (label != src_data.npos)
{
while (src_data.npos != label)
{
label_next = src_data.find(sign,label+1);
if(label == 0)
{
if(label_next - label == 1)
{
label_next = src_data.find(sign,label_next+1);
str_temp.assign(src_data,2,label_next-2);
}else
{
str_temp.assign(src_data,label+1,label_next-label-1);
}


if (str_temp != "")
{
data.insert(std::map<int,string>::value_type(num++,str_temp));
}
label = label_next+1;
label_p = label;
}else
{
str_temp.assign(src_data,label_p,label-label_p);
if (str_temp != "")
{
data.insert(std::map<int,string>::value_type(num++,str_temp));
}
label_p = label+1;
label = label_next;
}


}
str_temp.assign(src_data,label_p,src_data.length()-label_p);
if (str_temp != "")
{
data.insert(std::map<int,string>::value_type(num++,str_temp));
}
}else
{
str_temp = src_data;
if (str_temp != "")
{
data.insert(std::map<int,string>::value_type(num++,str_temp));
}


}
//int ss = 0;


}
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页