C ++如何获取其索引的位置后获取子字符串 [英] C++ how to get substring after get position of its index

查看:215
本文介绍了C ++如何获取其索引的位置后获取子字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想解析此网页

string str2 ("<span class=\"time_rtq_ticker\"><span id=\"yfs_l10_usdsgd=x\">");
  size_t found;

  // different member versions of find in the same order as above:
  found=sdata.find(str2);
  if (found!=string::npos)
    cout << "first 'needle' found at: " << int(found) << endl;

如果我得到needle的位置,我希望它停止解析之后

How can i obtain the Currency rate after i get the position of "needle" which is the pattern, i want it stop parsing after

对不起,我这样做为我的一个小项目,不商业,只是一些小工作

Sorry i am doing this for a small project of mine, not commercial, just some mini work

推荐答案

std :: string.substr(pos,npos)会给你 std :: string 从长度 npos 的pos(找到)。要找出长度,您可能需要查找字符串< (下一个html标签的开头)并减去。

std::string.substr(pos,npos) will give you the std::string from pos (found in your case) with length npos. To find out the length you might have to look for the string "<" (beginning of the next html tag) and subtract.

这篇关于C ++如何获取其索引的位置后获取子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆