C++之字符串分割函数split
2015-05-04 09:48
423 查看
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 = 0; size_t index=s.find_first_of(delim,last); while (index!=std::string::npos) { ret.push_back(s.substr(last,index-last)); last=index+1; index=s.find_first_of(delim,last); } if (index-last>0) { ret.push_back(s.substr(last,index-last)); } } //取vector的最后一个元素: std::string tmp = str_arr[str_arr.size()-1]; 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[0] << " second: "<< svec[1] << std::endl; } std::cout << "src string: " << str << std::endl; return 0; }
相关文章推荐
- C++字符串分割函数split实现
- 精简代码:Python的split方法函数可以分割字符串成列表,默认是以空格作为分隔符sep来分割字符串。
- c++编写字符串分割函数
- C/C++实现split分割字符串
- MySQL里实现类似SPLIT的分割字符串的函数
- C++ string类型的split字符串分割函数
- hive函数 -- split 字符串分割函数
- PHP 字符串分割 explode 与 str_split 函数
- How to split string in C++(分割字符串)
- java split()函数对字符串分割(通过空格)!
- python之正则表达式之简单分割字符串split()函数
- c++ string split分割字符串
- Delphi自带的字符串分割函数Split
- C++之split字符串分割
- 数据库split字符串分割和trim去除空格的表值函数
- C++:实现split分割字符串
- C++:实现split分割字符串
- Java中用split()函数进行分割字符串
- C++ 字符串分割 split