split()根据关键字符分割字符串 →_→还在码代码的马子耕←_←
来源:互联网 发布:电力数据通信网 编辑:程序博客网 时间:2024/05/05 02:59
=======================================================================
联系方式
qq:3110057340
邮箱:mazigeng@qq.com
新浪微博:还在码代码的马
=======================================================================
=============说明=============
/********************
* 功能:根据给定的关键字符cKey值,来分割字符串str。
* 将分好的字符串通过list列表outSL传出。
* outSL中为每一个分割好的子串,所有子串中均不保护cKey值。
* 参数:outSL 存放子串的buff
* str 待分割的字符串
* cKey 分割的关键字
* 返回:无
* ******************/
=============拿来就用函数 (ASCII)=============
void splitA(list<string>& outSL, string str, char cKey)
{
// 打入结尾岗哨
str.push_back(cKey);
int fpos = -1;
do{
int bpos = str.find(cKey,fpos+1);
int n = bpos - fpos - 1;
string strSub = str.substr(fpos+1, n);
if(!strSub.empty())
outSL.push_back(strSub);
fpos = bpos;
}while(fpos != (int)(str.length() - 1));
}
=============拿来就用函数 (UNICODE)=============
void splitW(list<wstring>& outSL, wstring str, wchar_t cKey)
{
// 打入结尾岗哨
str.push_back(cKey);
int fpos = -1;
do{
int bpos = str.find(cKey,fpos+1);
int n = bpos - fpos - 1;
wstring strSub = str.substr(fpos+1, n);
if(!strSub.empty())
outSL.push_back(strSub);
fpos = bpos;
}while(fpos != (int)(str.length() - 1));
}
=============用例=============
int main()
{
wstring strTest = L"Hello world this is split function";
list<wstring> retList;
split(retList, strTest, L'l'); // 以l为关键字
while(retList.begin() != retList.end())
{
wcout << retList.front() << endl;
retList.pop_front();
}
return 0;
}
输出结果:
He
o wor
d this is sp
it function
=============头文件=============
#include <list>
#include <string>
using std::list;
using std::string;
using std::wstring;
- split()根据关键字符分割字符串 →_→还在码代码的马子耕←_←
- [C/C++标准库]_[初级]_[分割字符串Split]
- 字符串根据多个字符进行分割的一种方法(使用split而不是regex.split更不是replace)
- 根据分割字符,获得分割字符后面的字符串
- String.split()_转义字符
- java中用String.split()分割含有特殊字符的字符串
- Split 获取字符串中指定符号分割的字符内容
- ORACLE(PL/SQL) 根据字符分割(SPLIT)字符串返回数组
- 分割字符串(字符串的split)
- SQL实现split函数,自定义分割字符,自定义取出第几个分割字符前的字符串
- 字符串字符分割代码
- java分割字符串(特殊字符) split
- split的坑-字符串分割
- java中用split()方法分割字符串--用特殊字符分割得不到想要的结果的情况
- 根据字符分割字符串的三种写法
- SQL根据字符分割字符串的三种写法
- js split 的用法和定义 js split分割字符串成数组的实例代码
- js split 的用法和定义 js split分割字符串成数组的实例代码
- 2024 C语言合法标识符
- window dos基本操作命令介绍
- 金九银十,浅谈关于java程序员面试的一些事项
- XMLParsing
- 【Struts2学习笔记(9)】单文件上传和多文件上传
- split()根据关键字符分割字符串 →_→还在码代码的马子耕←_←
- 神奇的Lua:可变参数
- NSAttributedString
- 搭建Hadoop环境----CentOs安装和配置(二)
- android驱动例子(LED灯控制)
- 善用指针---指针数组
- mysql中date与datetime的区别
- Unity 3D 文件导入出错
- Android Support V4, V7, V13的作用与用法