c++ 字符串切割
来源:互联网 发布:翻墙 mac 免费 2017 编辑:程序博客网 时间:2024/06/16 01:53
life is short, 唉!
demo1:
需求 “hello#world!” 按 ‘#’切割并输出, 注意这里我们知道是一个分隔符切成两段,比较简单。
#include <string>#include <vector>std::vector<std::string> split(std::string str,std::string pattern){ std::string::size_type pos; std::vector<std::string> result; pos=str.find(pattern,0); std::string s=str.substr(0,pos); result.push_back(s); std::string s2 = str.substr(pos+1,str.size()); result.push_back(s2); return result;}int main(){ std::string s = "hello#world!"; std::vector<std::string> results = split(s, "#"); for(int i=0; i<results.size();i++){ std::cout << results[i] << std::endl; }}
demo2:
稍微复杂一点,比如一个网址 “http://blog.csdn.net/zjm750617105/article/details/62426843” 按 “/” 切割:
有点事,晚上补
0 0
- [C]切割字符串
- C/C++切割字符串
- C语言字符串切割函数strtok_s()
- 字符串切割
- 字符串切割
- 切割字符串
- 字符串切割
- 切割字符串
- 切割字符串
- //切割字符串
- 字符串切割
- 字符串切割
- 切割字符串
- C/C++--字符串切割及去两端空格
- c语言入门:指针运用 (用逗号切割字符串)
- LeetCode之字符串(C++)的切割简单实现
- C语言中字符串处理小案例(切割)
- 字符串切割Split()
- Spring-bean的生命周期
- 子类父类 构造函数析构函数
- LeetCode 题解(Week6):300. Longest Increasing Subsequence
- RT-Thead SHELL 命令段定义实现方法
- amr格式解析
- c++ 字符串切割
- 通过观测到的公交车线路估计城市共有多少路公交车
- 数据库触发器
- iOS app版本迭代(iOS中app在iTunes中更新版本流程)
- VS中MFC连接MySQL由于系统不同位(32/64)引起的错误:无法解析的外部符号 _mysql_init@4、_mysql_query
- 读《统计自然语言处理》——词汇获取
- 代码混淆之道(一)
- QiYuAdmin-Centos安装和配置FastDFS
- 【Leetcode】45. Jump Game II