c++之字符串分割:

 /*
*c++之字符串分割:
*/ #include <iostream>
#include <string>
#include <vector> void split(const std::string& s, const std::string& delim,std::vector< std::string >& ret)
{
size_t last = ;
size_t index=s.find_first_of(delim,last);
while (index!=std::string::npos) {
ret.push_back(s.substr(last,index-last));
last=index+;
index=s.find_first_of(delim,last);
}
if (index-last>) {
ret.push_back(s.substr(last,index-last));
}
} //取vector的最后一个元素:
std::string tmp = str_arr[str_arr.size()-]; int main()
{
std::string str = "test/jjksdf";
if(str.find("/") != std::string::npos){
std::vector<std::string> svec;
split(str, "/", svec);
std::cout << "first:" << svec[] << " second: "<< svec[] << std::endl;
}
std::cout << "src string: " << str << std::endl; return ;
}

C++之字符串分割函数split的更多相关文章

  1. JavaScript中字符串分割函数split用法实例

    这篇文章主要介绍了JavaScript中字符串分割函数split用法,实例分析了javascript中split函数操作字符串的技巧,非常具有实用价值,需要的朋友可以参考下 本文实例讲述了JavaSc ...

  2. C++常见问题: 字符串分割函数 split

    C++标准库里面没有字符分割函数split ,这可太不方便了,我已经遇到>3次如何对字符串快速分割这个问题了.列几个常用方法以备不时之需. 方法一: 利用STL自己实现split 函数(常用,简 ...

  3. Delphi 自带的字符串分割函数split

    下面介绍Delphi自带的字符串分割函数,根据你的需要来使用. 1.ExtractStrings function ExtractStrings(Separators, WhiteSpace: TSy ...

  4. (转)C++常见问题: 字符串分割函数 split

    http://www.cnblogs.com/dfcao/p/cpp-FAQ-split.html C++标准库里面没有字符分割函数split ,这可太不方便了,我已经遇到>3次如何对字符串快速 ...

  5. Java字符串分割函数split源码分析

    spilt方法作用 以所有匹配regex的子串为分隔符,将input划分为多个子串. 例如: The input "boo:and:foo", for example, yield ...

  6. SQL Server自定义字符串分割函数——Split

    我相信大部分人都碰到过,处理数据的时候,字段的值是以 ',' (逗号)分隔的形式,所以我也不能避免. 然后我才知道,sql 是没有类似于 C# 和 Javascript 这种分割字符串的方法.( Sp ...

  7. hive函数 -- split 字符串分割函数

    hive字符串分割函数 split(str, regex) - Splits str around occurances that match regexTime taken: 0.769 secon ...

  8. Split字符串分割函数

    非常非常常用的一个函数Split字符串分割函数. Dim myTest myTest = "aaa/bbb/ccc/ddd/eee/fff/ggg" Dim arrTest arr ...

  9. ASP.NET中常用的字符串分割函数

    asp.net字符串分割函数用法 先来看个简单的实例 但是其数组长度却是25,而不是3.下面这种方法是先将“[111cn.net]”替换成一个特殊字符,比如$,在根据这个字符执行Split 例如下面我 ...

随机推荐

  1. java中如何获取系统时间

    需要引入的包有: import java.util.Date; 此为获取当前系统时间,合适为“1991-01-01” String now = "";    SimpleDateF ...

  2. java 写文件解析

    import java.io.File; import java.io.FileOutputStream; import java.io.*; public class FileTest { publ ...

  3. js面向对象的三大特性

    0x00:使用OOP技术,常常要使用许多的代码模块,每个模块都提供特定的功能,每个模块老师孤立的,甚至与其它的模块完全独立,这种模块化的编程方法大大的提供了代码实现的多样性,大大增加了代码的重用性.j ...

  4. 【LeetCode题意分析&解答】33. Search in Rotated Sorted Array

    Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 migh ...

  5. python自学笔记(五)python文本操作

    一.python自带方法 r:read 读 w:write 写 a:append 尾行追加 先命令行进入python后 >>>d = open('a.txt','w') #在对应路径 ...

  6. C# Convert an enum to other type of enum

    Sometimes, if we want to do convert between two enums, firstly, we may think about one way: var myGe ...

  7. ElasticSearch 插件配置

    http://blog.sina.com.cn/s/blog_8f31e5b10101dsnq.html http://www.tuicool.com/articles/mMZfu2 http://b ...

  8. CI URL 辅助函数 url helper

    URL 辅助函数文件包含一些在处理 URL 中很有用的函数 加载辅助函数 本辅助函数通过如下代码加载: $this->load->helper('url'); 可用函数如下: site_u ...

  9. 求最大值最小值的方法 时间复杂度O(n)

    #include<iostream> #include <iostream> #include <bitset> #include <ctime> us ...

  10. python异常处理try,except,else,finally,raise

    先看下else的使用: try: ... exception: ... else: ... 只有在try中没有发生任何异常,所有代码完全成功的情况下才会转入else 再看下finally: final ...