您的位置:首页 > 其它

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

2015-06-25 23:15 507 查看
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;

}

http://192.168.1.108:88/my/test/func?
筛选出其中的func /IP /PORT等等信息
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: