C 截取字符串

本文介绍了一个用于将字符串按指定字符拆分成数组的C++函数。该函数通过不断查找指定字符的位置来实现字符串的拆分,并将每次拆分得到的子字符串存入字符串数组中。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include #include //+------------str is the String that will be split---------------+// //+------------bystr is the string by which to split str----------+// //+------------str_array is the array to save splited str---------+// void split(const CString str,const CString bystr,CStringArray *str_array) { int nLen = bystr.GetLength(); int preLoc = 0; int nowLoc = 0; while(true) { nowLoc = str.Find(bystr,preLoc); if(nowLoc == -1&&preLoc == 0) { CString substr3=str; str_array->Add(substr3); break; } if(nowLoc == -1&&preLoc != 0) { CString substr2=str.Mid(preLoc); str_array->Add(substr2); break; } CString substr = str.Mid(preLoc,nowLoc-preLoc); str_array->Add(substr); preLoc=nowLoc + nLen; } }  
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值