Like under:
CString strOrg;
strOrg="1/2/33/4/5/6";
I wanna output:
1
2
33
4
5
6
and it's better to split the string into a string array
for your help,there are a "thanks" only
CString strOrg;
strOrg="1/2/33/4/5/6";
I wanna output:
1
2
33
4
5
6
and it's better to split the string into a string array
for your help,there are a "thanks" only
CString a[MaxNum];
CString strOrg,strTemp,str;
strOrg="1/2/33/4/5/6";
int n=strTemp.Find(_T('//'));
int i=0;
while(n!=-1)
{
a[i++]=strTemp.Left(n);
str=strTemp.Right(strTemp.GetLength()-n-1);
strTemp=str;
n=strTemp.Find(_T('//'));
}
strtok
that's good
#include <iostream.h> int nBegin=0, nEnd;
CStringArray strAry;
char subStr[20];
char org[100] = ("1/2/33/4/5/6");
CString strOrg(org);
do
{
nEnd = strOrg.Find('/', nBegin);
if ( -1 != nEnd )
{
memcpy(subStr, org+nBegin, nEnd);
subStr[nEnd-nBegin] = '\0';
CString temp(subStr);
strAry.Add(temp);
nBegin = nEnd+1;
}
}while (-1 != nEnd ); int nCount = strAry.GetSize();
for (int i=0; i<nCount; ++i)
{
cout << (LPCTSTR)strAry.GetAt(i) << endl;
}
Find the next token in a string.char *strtok( char *strToken, const char *strDelimit );wchar_t *wcstok( wchar_t *strToken, const wchar_t *strDelimit );unsigned char *_mbstok( unsigned char*strToken, const unsigned char *strDelimit );
#include <stdio.h>
#include <windows.h>
#include <iostream.h>
char seps[]="/";
char *token;void main( void )
{
char string1[]="1/2/33/4/5/6"; printf( "%s\n\nTokens:\n", string );
token = strtok( string, seps );
while( token != NULL )
{
cout<<token;
token = strtok( NULL, seps );
}
cout<<buff;
}你只要先把你的CString转换成char*类型就OK了