【字符串操作】截取字符串
2015-06-25 23:15
507 查看
eg:截取一段字符串中的若干信息
http://192.168.1.108:88/my/test/func?
筛选出其中的func /IP /PORT等等信息
#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等等信息
相关文章推荐
- Lua面向对象编程系列-通过Table和Closure来实现类机制
- TCP带外数据学习总结(概念,发送接收过程,数据到达检测,代码实现)
- 使用本地JConsole监控远程JVM(最权威的总结)
- linux下vi编辑文件
- Halcon相机标定
- 创建和遍历二叉树
- RxJava概述
- [Java]学习笔记,随笔【二】
- LintCode-搜索区间
- 51Nod 1060 最复杂的数
- 数据结构概述
- Halcon标定步骤
- Robot Framework中对出错用例处理的策略
- Centos学习笔记之grep命令
- 安装DB2 FIXPACK
- [LeetCode] Basic Calculator II 基本计算器之二
- Robot Framework中对出错用例处理的策略
- Halcon学习标定助手
- java学习第一个程序HelloWorld
- Eclipse快捷键大全