读书人

关于字符数组 查寻、分割

发布时间: 2012-10-25 10:58:57 作者: rapoo

关于字符数组 查找、分割
有这么一串数据:

C/C++ code
"Action:InfCtrNet\r\nInfCtrCmd:callmst\r\nDisplayNumber:11000\r\n\r\n"


是发送过来。将其接收到后放入一个字符数组中。

C/C++ code
char CallDevice[] = {"Action:InfCtrNet\r\nInfCtrCmd:callmst\r\nDisplayNumber:11000\r\n\r\n"};



现在需要将其中的nDisplayNumber:后面的数字取出来。应该怎么操作,可能用到那些函数。

[解决办法]
CString cs(CallDevice);
int nPos = cs.Find( _T('DisplayNumber') );
if( nPos < 0 )
return FALSE;
int nPos2 = cs.Find( _T('\r\n\r\n') );
if( nPos2 < 0 )
return FALSE;
return cs.Mid(npos,nPos2 - nPos2); //get 11000
[解决办法]
tmp是地址
[解决办法]
C/C++ code
#include <afx.h>#include <iostream.h>void main( void ){    CString str = "Action:InfCtrNet\r\nInfCtrCmd:callmst\r\nDisplayNumber:11000\r\n\r\n";    char *seps  = "DisplayNumber:";    CString temp = str.Right(str.GetLength()-str.ReverseFind(':')-1) ;    cout<< temp <<endl;} 

读书人网 >VC/MFC

热点推荐