【字符串操作】截取字符串

来源:互联网 发布:mac电脑双系统切换 编辑:程序博客网 时间:2024/04/30 02:49

eg:截取一段字符串中的若干信息

  

#include <stdio.h>#include <iostream>#include <regex>using namespace std;void main(){string strsrc = "http://192.168.1.108:88/my/test/func?";int pos = strsrc.rfind("/");if (string::npos != pos){string strfunc = strsrc.substr(pos+1).data();strfunc = strfunc.erase(strfunc.length()-1, 1);<span style="white-space:pre"></span>//FUNC string strurl = strsrc.substr(0, pos);}int poshttp = strsrc.find("http://");int posport = strsrc.rfind(":");if (string::npos != poshttp && string::npos != posport && (posport - poshttp) > strlen("http://")){string strip = strsrc.substr(poshttp+7, posport-poshttp-7);//获取ipstring strport = strsrc.substr(posport+1).data();int posported = strport.find("/");if (string::npos != posported){strport = strport.substr(0, posported);//获得端口int port;sscanf(strport.data(), "%d", &port);//端口转化为int//scanf获取屏幕输出源int abc =0 ;abc++;}}return;}


http://192.168.1.108:88/my/test/func?

筛选出其中的func /IP /PORT等等信息

0 0
原创粉丝点击