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); //获取ip
string 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;
}
筛选出其中的func /IP /PORT等等信息