当前位置:网站首页>CString string splitting function
CString string splitting function
2022-06-10 09:07:00 【Pepsi__】
This is a passage written by the great God to realize CString String segmentation function code
#include <vector> // Reference header file
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; // Maximum segmentation length
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; // Traverse to get the minimum of all separators Index
}
if (i == sep_number-1 && smallIndex != MAX_COUNT) // After traversing all the delimiters
{
szLeft = szRight.Left(smallIndex);
szLeft.Trim(); // Remove the space
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();
}
Although I don't understand how it is realized , But the way to use it is
char separator[2] = {':', '.'};
CString strTime = "00:10:22.43";
vector<CString> arrayText;
SplitCString(strTime ,separator,sizeof(separator),arrayText);
arrayText The container will contain the four pieces that have been divided CString:“00”、“10”、“22”、“43”. The characters used as segmentation marks are stored in separator In an array . The string used for segmentation is strTime.
Reference article :
CString String segmentation ( Multiple characters as separator )
边栏推荐
- Linear Regression
- C#入门系列(十) -- 一维数组
- Principal Component Analysis
- After Zotero beta 6.0 is installed, the problem that the built-in PDF reader cannot be used is solved
- C # introductory series (10) -- one dimensional array
- 视频|乐鑫研发说
- Win11 installing pandoc
- Is it safe to open a stock account by mobile phone?
- Textstudio displays line numbers and does not check spelling settings
- How to open an account for your own stock trading? Is it safe?
猜你喜欢

Rotate linked list

QQ微信实现连续发送消息【代码实现】

Exemple de référence AWS IOT de lexine pour esp32 - C3

Credit card customer churn forecast

文件如上图所示,怎么用navicat打开一个数据库文件

How to Understand Your Data With Visualization

How to Spot-Check Classification Algorithms

在 Kubernetes 中基于 StatefulSet 部署 MySQL(上)

How knowledge atlas, graph data platform and graph technology help the rapid development of retail industry

How to Spot-Check Regression Algorithms
随机推荐
vtk学习之PipelineExecute管线的执行过程
顶流编辑器 Atom,将于 12 月 15 日退出历史舞台
texstudio 如何编译运行基于markdown宏包的tex文件
Latex基本语法备注
Zotero beta 6.0版本安装后,无法使用内置pdf阅读器的问题解决
AWS IOT reference example of Lexin launching esp32-c3
How far is your team from continuous deployment in 2022?
如何在使用 Flutter时切换应用时隐藏应用预览
All the contents of the page in row units are segmented in rows
Rendercylinder lights for VTK learning
Mmsegment Series III (basic network architecture and pre training model)
对线HR_MySQL逻辑架构?就这?
Is it safe to open a stock account by mobile phone?
乐鑫 ESP RainMaker 加速企业智能转型,私有云方案助力客户打造自有品牌
Auto. JS Pro development environment configuration
wechat_ Configuration of wechat applet subcontracting
HP 笔记本电脑 - 笔记本电脑睡眠后如何唤醒
Task05:SQL高级处理
Hardware flow control RTs and CTS in UART
Texstudio how to compile and run tex files based on markdown macro package