_bstr_t GetMid(LPCTSTR lpSrc,LPCTSTR lpStart1,LPCTSTR lpStart2,LPCTSTR lpszEnd,BOOL IsIncludeStart = FALSE)
{
_bstr_t _tszTmp;
CString szStart1=lpStart1;
CString szStart2=lpStart2;
int nStartCount = 0; //开始字节数
int nTmpCount = szStart1.GetLength();
if ( (lpStart1 == NULL) || (lpszEnd == NULL) ){
return _tszTmp;
}
LPCTSTR lpPS = StrStr(lpSrc,lpStart1);
if (lpPS == NULL){
return _tszTmp;
}
if (lpStart2 != NULL)
{
LPCTSTR lptmp = StrStr(lpPS,lpStart2);
if (lptmp == NULL){
return _tszTmp;
}
lpPS = lptmp;
//如果开始字符串2不为空,那么开始的字节数就要设置为字符串二的字节数了
nTmpCount = szStart2.GetLength();
}
LPCTSTR lpPE = StrStr(lpPS,lpszEnd);
if (lpPE == NULL){
return _tszTmp;
}
if (!IsIncludeStart)
{
nStartCount = nTmpCount;
}
CString szRet(lpPS+nStartCount,lpPE-lpPS-nStartCount);
_tszTmp = szRet;
return _tszTmp;
}
VOID testmid()
{
CString szData = "<a>---<cd>safedebug</a>";
CString szOut = (LPCTSTR)GetMid(szData,"<a>","<cd>","</a>");
printf("%s\n",szOut);
}
取文本中间
最新推荐文章于 2024-07-08 03:15:56 发布