来自

http://www.cnblogs.com/dfcao/p/cpp-FAQ-split.html

http://blog.diveinedu.com/%E4%B8%89%E7%A7%8D%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%88%86%E5%89%B2%E6%96%B9%E6%B3%95cc/

利用STL函数进行字符串分隔

涉及到string类中的的两个函数,find和substr

1,find函数(查找子字符串第一次出现的位置)

size_type find( const basic_string& str, size_type pos =  ) const;

str,表示目标字符串

pos,从pos位置开始

返回值:返回子串第一次出现的位置,否则返回string::npos尾后位置

2,substr函数(获得子字符串)

basic_string substr( size_type pos = ,size_type count = npos );

pos,子字符串第一个字符的位置

count,子字符串中的长度,默认值为npos,npos就是 s的尾后位置

返回值是一个 字符串,即s [ pos, pos_count ),左闭右开。

在编程语言中,这个度:s.substr(pos, sizeof(sub) )

可以这么实现

class A{
void myslipt(string &s,vector<string> &re,string &c){
std::string::size_type pos1,pos2;
pos2 = s.find(c);///find
pos1 = ;
while(std::string::npos != pos2){
re.push_back(s.substr(pos1,pos2-pos1));///[p1,p2)
pos1 = pos2+c.size();
pos2 = s.find(c,pos1);
}
if(pos1!=s.length()){
re.push_back(s.substr(pos1));
}
} void test(ListNode *head){
cout<<"begin test...\n";
string str = "this is a string";
string c = "is";
vector<string> re;
myslipt(str,re,c);
for(auto i: re){
cout<<"|"<<i<<"|"<<endl;
}cout<<endl; cout<<"end test...\n";
}
};
begin test...
|th|
| |
| a string| end test...

c++ 中的slipt实现的更多相关文章

  1. Python开源框架

    info:更多Django信息url:https://www.oschina.net/p/djangodetail: Django 是 Python 编程语言驱动的一个开源模型-视图-控制器(MVC) ...

  2. javascript中slipt()分割

    slipt()分割取长度 例子1: n变量其实只有两个1,结果分割成数组有3个,所以结果页取1长度的话要减去1 l 异步请求data数据输出是html,当要获取数据长度的时候, 用解析html获取长度 ...

  3. 关于UI自动化中元素定位常用方法的个人总结

    1.如果目标元素有id属性,优先使用id定位: 2.元素locator尽可能保证简洁,考虑locator中路径的变化频率,尽量减少后期更新和维护成本: 3.使用xpath时,不要一味的使用‘/’逐层进 ...

  4. 1、Python中的正则表达式(0601)

    回顾: 1.文件对象: open('file','mode','bufsize') read,readline,readlines,write,writelines,flush,seek,tell 2 ...

  5. Python3中的输入输出

    input()函数 我们可以通过Python3解释器查看Python3中input()的含义: >>> type(input) <class 'builtin_function ...

  6. mapreduce中一个map多个输入路径

    package duogemap; import java.io.IOException; import java.util.ArrayList; import java.util.List; imp ...

  7. Hadoop 中利用 mapreduce 读写 mysql 数据

    Hadoop 中利用 mapreduce 读写 mysql 数据   有时候我们在项目中会遇到输入结果集很大,但是输出结果很小,比如一些 pv.uv 数据,然后为了实时查询的需求,或者一些 OLAP ...

  8. Python中的多进程与多线程(一)

    一.背景 最近在Azkaban的测试工作中,需要在测试环境下模拟线上的调度场景进行稳定性测试.故而重操python旧业,通过python编写脚本来构造类似线上的调度场景.在脚本编写过程中,碰到这样一个 ...

  9. .NET Core中的认证管理解析

    .NET Core中的认证管理解析 0x00 问题来源 在新建.NET Core的Web项目时选择“使用个人用户账户”就可以创建一个带有用户和权限管理的项目,已经准备好了用户注册.登录等很多页面,也可 ...

随机推荐

  1. java 串口通信实现流程

    1.下载64位rxtx for java 链接:http://fizzed.com/oss/rxtx-for-java 2.下载下来的包解压后按照说明放到JAVA_HOME即JAVA的安装路径下面去 ...

  2. [Rodbourn's Blog]How to export Excel plots to a vector image (EPS, EMF, SVG, etc.)

    This is a bit of a workaround, but it's the only way I know of to export an Excel plot into a vector ...

  3. django建议入门-FYI

    django 简易博客 现在正式开始博客开发 1安装官方发布版 官方发布的版本带有一个版本号,例如1.0.3或1.1,而最新版本总是可以在http://www.djangoproject.com/do ...

  4. Object comparison - (BOOL)isEqual:(id)other

    https://developer.apple.com/library/content/documentation/General/Conceptual/DevPedia-CocoaCore/Obje ...

  5. 【BZOJ1833】[ZJOI2010] count 数字计数(数位DP)

    点此看题面 大致题意: 求在给定的两个正整数\(a\)和\(b\)中的所有整数中,\(0\sim9\)各出现了多少次. 数位\(DP\) 很显然,这是一道数位\(DP\)题. 我们可以用前缀和的思想, ...

  6. Drupal忘记管理员密码

    第一步:登陆录到phpmyadmin(通用的mysql数据库管理工具),进入phpmyadmin后,找到与drupal7相关联数据库并在数据库中找到一张名为“users”的表,然后选择浏览. 第二步: ...

  7. vue-cli npm run build 打包问题 webpack@3.6

    1, vue-router 路由 有两个模式 (mode) hash (默认模式) 使用URL来模拟一个完整的URL 但是没个URL都会带上 "#/'' 支持所有浏览器 这个模式使用 red ...

  8. python 时间加8小时后的时间

    eta_temp = one['arrival'].encode('utf-8') fd = datetime.datetime.strptime(eta_temp, "%Y-%m-%dT% ...

  9. shell数组脚本

    #!/bin/bash array=( ) ;i<${#array[*]};i++)) do echo ${array[i]} done 脚本2 #!/bin/bash array=( ) fo ...

  10. mysql零散操作

    添加对外用户 CREATE USER 'admin'@'%' IDENTIFIED BY '!QAZ2wsx'; GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%'; ...