字符串处理

#include <iostream>
#include <vector>
using namespace std;

void output(vector<string> v, int index);
void output(vector<string> v, int index)
{
 if (index <= v.size())
 cout << v.at(index);
}

int main()
{
 char* pStr = "209{a{{{/10/8/7/9/3/1{{1{table$222{b{{12/3/a/123/d{88{div$";
 
 string index = "";
 string name = "";
 string path = "";
 string id = "";
 string tag = "";
 vector <string> vec_in;
 vector <string> vec_na;
 vector <string> vec_pa;
 vector <string> vec_id;
 vector <string> vec_ta;
 
 int j = 0;
 int q = 0;
 int i = 0;
 
 while ('\0' != pStr[i])
 {
  if ('$' == pStr[i])
  {
   vec_in.push_back(index);
   vec_na.push_back(name);
   vec_pa.push_back(path);
   vec_id.push_back(id);
   vec_ta.push_back(tag);
   
   index = "";
         name = "";
         path = "";
         id = "";
         tag = "";
   
   j++;
   i++;
   q = 0;
   continue;
  }
  
  else if ('{' == pStr[i])
  {
   if (i>=1)
   {
     if ( '{' != pStr[i-1])
     {
         q++;
      i++;
      continue;
     }
     else
     {
     i++;
     continue;
     }
   }
        
   
  }
  
  else
  {
   if ( 0 == q)
      {
    index += pStr[i];
      }
      else if ( 1 == q)
      {
    name += pStr[i];
      }
      else if ( 2 == q)
      {
    path += pStr[i];
      }
      else if ( 3 == q)
      {
    id += pStr[i];
      }
      else
      {
    tag += pStr[i];
      }
  }
  
  i++;
 }
 
 vec_in.clear();
 vec_na.clear();
 vec_pa.clear();
 vec_id.clear();
 vec_ta.clear();
 system("pause");
 return 0;
}

 

 

一个字符串,以‘$’分组。每组数据包括index name path id tag 分别将对应数据存到index name path id tag 标签里


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值