本文整理汇总了C++中Tstring::substr方法的典型用法代码示例。如果您正苦于以下问题:C++ Tstring::substr方法的具体用法?C++ Tstring::substr怎么用?C++ Tstring::substr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tstring
的用法示例。
在下文中一共展示了Tstring::substr方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AdvancedMach
//2,高级过滤 L=20|01=0C|02=0B|20=CC|IP=211.1.1.1|P=9900 条件必须都要满足
BOOL CGPacket::AdvancedMach(Tstring& str)
{
std::map<Tstring, Tstring> matchmap;
int splitpos = 0, pos = 0;
while (TRUE)
{
splitpos = str.find(_T('|'), pos);
Tstring strSub;
if (Tstring::npos != splitpos)
{
strSub = str.substr(pos, splitpos - pos);
}
else {
strSub = str.substr(pos);
}
int assignpos;
assignpos = strSub.find(_T('='));
if (Tstring::npos != assignpos) {
Tstring key, value;
key = strSub.substr(0, assignpos);
value = strSub.substr(assignpos+1);
matchmap[key] = value;
}
if (splitpos == Tstring::npos)
break;
pos = splitpos + 1;
}
//2,高级过滤 L=20|01=0C|02=0B|20=CC|IP=211.1.1.1|P=9900 条件必须都要满足
std::map<Tstring, Tstring>::iterator i;
for (i = matchmap.begin(); i != matchmap.end(); i++)
{
Tstring Key, Value;
Key = (*i).first;
Value = (*i).second;
if (Key == Tstring(_T("L"))) {
if (m_dwSize != _ttoi(Value.c_str()))
{
return FALSE;
}
}
else if (Key == Tstring(_T("IP"))) {
if (m_property.strIpAddr != Value)
{
return FALSE;
}
}
else if (Key == Tstring(_T("P"))) {
if (m_property.strPort != Value)
{
return FALSE;
}
}
else {
if (m_pBuf[_ttoi(Key.c_str())] != _ttoi(Value.c_str()))
{
return FALSE;
}
}
}
return TRUE;
}
示例2: PreProcessPackeTstring
Tstring CSendPage::PreProcessPackeTstring(Tstring& tstrStr )
{
Tstring tstrTemp, tstrRet;
Tstring::size_type posLeftBracket = 0, posRightBracket = -1;
posLeftBracket = tstrStr.find(_T("["));
if (posLeftBracket == Tstring::npos)
{
return tstrStr;
}
tstrRet = tstrStr.substr( 0, posLeftBracket);
ParseRightBracket:
DWORD dwBracketDataSize;
posRightBracket = tstrStr.find(_T("]"), posLeftBracket);
if (posRightBracket == Tstring::npos)
{
return _T("");
}
dwBracketDataSize = posRightBracket - posLeftBracket -1 ;
tstrTemp = tstrStr.substr(posLeftBracket + 1, dwBracketDataSize);
TCHAR tszTemp[1024];
INT iInc;
TCHAR tszBracket[32], tszNum[32];
TCHAR ch, *ptStr, sign;
int i, j, flag;
i=0, j=0, flag=0;
ptStr = (TCHAR*)tstrTemp.c_str();
do{
ch = *ptStr++;
if(ch == _T('+') || ch == _T('-'))
{
sign = ch;
flag = !flag;
}
else if(!flag)
{
tszBracket[i++] = ch;
}else
{
tszNum[j++] = ch;
}
}while(ch != _T('\0'));
tszBracket[i] = _T('\0');
tszNum[j] = _T('\0');
//todo inc or dec the string
tstrRet += Tstring(tszBracket);
BYTE *pHexBuf = new BYTE[i];
DWORD dwSelHexSize = Utility::StringLib::Tstring2Hex(tszBracket, pHexBuf);
switch (dwSelHexSize)
{
case 1:
*pHexBuf += (sign == _T('+') ? _ttoi(tszNum) : 0 - _ttoi(tszNum));
break;
case 2:
*(WORD*)pHexBuf = htons(htons(*(WORD*)pHexBuf) + (sign == _T('+') ? _ttoi(tszNum) : 0 - _ttoi(tszNum)));
break;
case 4:
*(DWORD*)pHexBuf = htonl(htonl(*(DWORD*)pHexBuf) + (sign == _T('+') ? _ttoi(tszNum) : 0 - _ttoi(tszNum)));
break;
default:
delete[]pHexBuf;
return _T("");
}
tstrTemp = Utility::StringLib::Hex2Tstring(pHexBuf, dwSelHexSize);
delete[]pHexBuf;
tstrTemp = Tstring(_T("[")) + tstrTemp + (sign == _T('+') ?Tstring(_T("+")):Tstring(_T("-"))) + Tstring(tszNum) + Tstring(_T("]"));
tstrStr.replace(posLeftBracket, dwBracketDataSize + 2, tstrTemp);
posLeftBracket = tstrStr.find(_T("["), posRightBracket);
if (posLeftBracket != Tstring::npos){
tstrRet += tstrStr.substr( posRightBracket+1, posLeftBracket - posRightBracket - 1 );
goto ParseRightBracket;
}else
{
tstrRet += tstrStr.substr( posRightBracket+1 );
}
return tstrRet;
}