//获取到'|'分隔后,元素的个数,如示例代码中,|分隔后,元素数为3
#include <afxdisp.h>
#include <stdio.h>
#include <tchar.h>
#include <locale.h>
CString str=_T("操作员,38d530a786319f0b,2016-2-19 7:12:50|审核员,10b29db7d7b6260a,2016-2-19 7:13:46|操作员,63a99f015106cd44,2016-2-19 9:6:50");
int main() {
int i,c,c1,L;
TCHAR t; _tsetlocale(LC_ALL,_T("chs"));
c1=-1;
c=0;
i=0;
L=_tcslen(str);
for (i=0;i<L;i++) {
t=str[i];
if (t==_T(',')) {
c++;
}
if (t==_T('|') || i==L-1) {
if (c1==-1) {
c1=c;
c=0;
} else {
if (c1!=c) {
_tprintf("|分隔的元素个数%d!=%d !\n",c1+1,c+1);
return 1;
}
c=0;
}
}
}
_tprintf("|分隔的元素个数%d\n",c1+1);
return 0;
}
//|分隔的元素个数3
//
#include <afxdisp.h>
#include <stdio.h>
#include <tchar.h>
#include <locale.h>
CString str=_T("操作员,38d530a786319f0b,2016-2-19 7:12:50|审核员,10b29db7d7b6260a,2016-2-19 7:13:46|操作员,63a99f015106cd44,2016-2-19 9:6:50");
int main() {
int i,c,c1,L;
TCHAR t; _tsetlocale(LC_ALL,_T("chs"));
c1=-1;
c=0;
i=0;
L=_tcslen(str);
for (i=0;i<L;i++) {
t=str[i];
if (t==_T(',')) {
c++;
}
if (t==_T('|') || i==L-1) {
if (c1==-1) {
c1=c;
c=0;
} else {
if (c1!=c) {
_tprintf("|分隔的元素个数%d!=%d !\n",c1+1,c+1);
return 1;
}
c=0;
}
}
}
_tprintf("|分隔的元素个数%d\n",c1+1);
return 0;
}
//|分隔的元素个数3
//
解决方案 »
- CListCtrl Report模式下,滚动条消息怎么获取?——————————求指导————————
- mfc俄罗斯方块。。有个drop函数不会写
- 关于将一个四边形中的点映射到另一个四边形中的问题
- cpu时间片如何细分
- 如何给View发送消息
- 把函数声明成const的,是何意义?
- BCGControlBar 6.0安装后居然用不了?
- ●当我的问题在MSDN里查不到解答时,怎么办?●
- 各位师兄,我一个类CMyWinThread是从CWinThred继承过来的,我想再建一个类继承CMyWinThread,但是在new class的时候无法选择到CMyWinThread,请指教,谢谢!
- 如何在vc中动态改变数组的大小,并且保留数组中的内容
- 2014-2-12到广州了,想找一份C++框架师的工作,所以恶补设计模式中。
- C++ List的迭代器可以定义成全局的吗
TCHAR str[]=_T("操作员,38d530a786319f0b,2016-2-19 7:12:50|审核员,10b29db7d7b6260a,2016-2-19 7:13:46|操作员,63a99f015106cd44,2016-2-19 9:6:50");
int a = _tcslen(_T("操作员,38d530a786319f0b,2016-2-19 7:12:50"));
int b = _tcslen(str)/a;
str.find(),
str.mid();
有这些库函数,楼主可以查MSDN啊
CString resToken(_T(""));
int curPos = 0;
LPCTSTR lpszToken = _T("|");
resToken= str.Tokenize(lpszToken, curPos); int nCount = 0;
while (resToken != _T(""))
{
AfxMessageBox(resToken);
resToken = str.Tokenize(lpszToken, curPos);
++nCount;
}
int nCount=0;
//while执行完成nCount就是查询到分隔符出现的次数
while( str.Find(_T("|")) > 0 )
{
str.Delete( 0, str.Find(_T("|"))+1 );
nCount++;
}
//元素个数是分隔符出现次数+1
nCount = nCount + 1;