#include <iostream>
#include <string>
int main()
{
/*Myvector<double> vec;
vec.push(1.1f);
system("pause");
return 0;*/
std::string user(" uid:600001, name:張三, score: 125, state:未準備");
std::string str("{act: login,result : true,room: {rid: 62,roomid : 608807,maxbet : 100,rounds : 10,redix: 0,remain : 10,state: 0},\
user:[{uid:600001, name: 張三, score : 125, state : 未準備},\
{ uid:600002, name : 李四, score : -125, state : 未準備 }]}");
std::string left;
int i = 0;
while (str.find(",") != std::string::npos)
{
/*int a = str.find("{");
if (a > -1)
{
str.erase(a,1);
}*/
i = str.find(",");
left = str.substr(0, i);
str = str.substr(i + 1);
if (left.find("{")!=std::string::npos)
{
left.erase(0,left.find("{")+1);
}
if (left.find("{")!=std::string::npos)
{
left.erase(0, left.find("{") + 1);
}
if (str.find("}") != std::string::npos)
{
left.erase(0,left.find("}")+1);
}
std::cout << left << std::endl;
}
if (str.find("}") != std::string::npos)
{
str.erase(str.find("}"));
}
std::cout << str << std::endl;
system("pause");
}
解析字符串substr
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.