当前位置:网站首页>CString字符串分割函数
CString字符串分割函数
2022-06-10 08:32:00 【百口可乐__】
这是一段大神写的用于实现CString字符串分割功能的代码
#include <vector> //引用头文件
using std::vector;
int SplitCString(const CString& str,const char * separator,int sep_number, vector<CString> &strArray)
{
strArray.clear();
int index = -1;
const int MAX_COUNT = 1000000; //最大分割长度
int smallIndex = MAX_COUNT;
CString szLeft;
CString szRight = str;
for (int i = 0; i< sep_number; i++)
{
index = szRight.Find(separator[i]);
if (index >= 0 && index < smallIndex)
{
smallIndex = index; //遍历获得所有的分割符的最小Index
}
if (i == sep_number-1 && smallIndex != MAX_COUNT) //遍历全部分割符之后
{
szLeft = szRight.Left(smallIndex);
szLeft.Trim(); //去除空格
if (!szLeft.IsEmpty()) strArray.push_back(szLeft);
szRight = szRight.Right(szRight.GetLength()-smallIndex-1);
szRight .Trim();
if (szRight.GetLength()>0)
{
i = -1;
smallIndex = MAX_COUNT;
}
else break;
}
else if (i == sep_number-1)
{
szRight.Trim();
if(!szRight.IsEmpty()) strArray.push_back(szRight);
}
}
return strArray.size();
}
虽然我看不懂是如何实现的,但是对于它的使用方法是
char separator[2] = {':', '.'};
CString strTime = "00:10:22.43";
vector<CString> arrayText;
SplitCString(strTime ,separator,sizeof(separator),arrayText);
arrayText容器里面就会存放被分割的四个CString:“00”、“10”、“22”、“43”。而作为分割标识的字符储存在separator数组里面。用于分割的字符串是strTime。
边栏推荐
- pinctrl子系统和gpio子系统
- Numpy version problem
- The R language uses the CS function of epidisplay package to calculate the value and confidence interval of relative risk (RR), generate the grouping data of exposure factor based on the pyramid funct
- What is unit testing and why
- What happens when your Huaqiangbei earphone falls into the water? How to restore sound quality?
- Test: friend circle like function
- 软件测试之WEB页面测试
- NaiveBayes function of e1071 package of R language constructs naive Bayes model, and confusionmatrix function of caret package is used to calculate confusion matrix (kappa, confidence interval, evalua
- 测试:杯子
- 黑马软件测试脑图
猜你喜欢

华为软件测试面试题 | 一位华为入职成功者的分享【笔试题】

pinctrl子系统和gpio子系统

【Lingo】运算符

接口测试怎么进行,如何做好接口测试

Sqlserver restore failed (the database is in use and cannot gain exclusive access to the database)

Computer level 2 test preparation MySQL day 4
![[lingo] solving equations](/img/4b/c54c4df3f9fb4675ab4fdca68e365b.png)
[lingo] solving equations

盘点新加坡旅游宣传片中不可错过的景点

Grafana server init failed: could not find config defaults, make sure HomePath command

idea jdbc报错
随机推荐
Software testing: 10 super practical testing rules known after work
想转行,为什么首选软件测试?
2022.06.07 learning contents
Elementary knowledge of optical flow method
Hardware flow control RTs and CTS in UART
接口测试怎么进行,如何做好接口测试
服务管理与通信,基础原理分析
What are the test case design methods?
【密码学】AES加解密
跳过51单片机,直接学STM32有什么严重后果
[lingo] solving equations
UART中的硬件流控RTS与CTS
The simplest way to merge and sort -- less than 15 lines
第2章 数据的表示和运算
华为软件测试面试题 | 一位华为入职成功者的分享【笔试题】
信用卡客户流失预测
How to conduct interface test and how to do interface test well
Implementation of a simplified MVVM
STM32 MPU 开发者的十大工作准则
完美人生PerfectLife——角色:Chenyuxin