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. 我们在 web 应用开发过程中经常遇到输出某种编码的字 符, 如 iso8859-1 等, 如何输出一个某种编码的字符串?

    public String translate (String str) { String tempStr = ""; try { tempStr = new String(str ...

  2. AOP annotation

    1.xml文件 <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http ...

  3. SQL Server 取前一天的0点和23点59分59秒

    DECLARE @startDate1 DATE; DECLARE @startDate DATETIME; ,@startDate1); ,CONVERT(DATETIME,@startDate1) ...

  4. js表格排序 & 去除字符串空格

    // a:列数 bool:排序升序判断参数 true false Str:支持多列 function newUnitSort(a, bool, str) { var oTable = document ...

  5. php mysql实现栏目分类递归

    header("content-type:text/html;charset=utf-8"); $dbhost = "localhost";   // 数据库主 ...

  6. linux 命令大全

    工作了一段时间,开始整理资料,好记性不如烂笔头啊. linux命令大全下载路径: 1.http://www.pc6.com/SoftView/SoftView_28912.html 2.http:// ...

  7. (Problem 70)Totient permutation

    Euler's Totient function, φ(n) [sometimes called the phi function], is used to determine the number ...

  8. Maven本地

    <localRepository></localRepository>

  9. html文件中文在浏览器中显示乱码问题解决

    利用浏览器打开html文件时,中文显示乱码,如下是原文件的内容 1 <html>   2         <head>   3             <title> ...

  10. poj 2001 Shortest Prefixes(字典树)

    题目链接:http://poj.org/problem?id=2001 思路分析: 在Trie结点中添加数据域childNum,表示以该字符串为前缀的字符数目: 在创建结点时,路径上的所有除叶子节点以 ...