字符串截取

int main()
{
#if 0
// 字符串截取1
string strSrc = "name:orange score:96 id:03c648578a6e79bdeaf2cb8ee2651424 e-mail:xxxx@xx.com ";
string::size_type nPos0 = strSrc.find("id:", 0);
if(nPos0 == string::npos) return -1;
nPos0 += 3;
string::size_type nPos1 = strSrc.find(" ", nPos0);
if(nPos1 == string::npos) return -1;
string strId = strSrc.substr(nPos0, nPos1 - nPos0 + 1);
cout << strId << endl;

// 字符串截取2
string str="第一 第二 第三 第四 第五";
string strTemp="";
vector<string> strVec;
int iPos0 = 0;
while (string::npos != str.find(" ", 0))
{
iPos0 = str.find(" ", 0);
strVec.push_back(str.substr(0,iPos0));
str = str.substr(iPos0+1,str.length()-iPos0);
}
// 最后一个字符串


system("pause");
return 0;
#endif

/*
//截取字符串,直到遇到换行
string::size_type nPos0 = DGI.find("DGI0101|", 0);
// if(nPos0 == string::npos) return -1;
nPos0 += 12;
string::size_type nPos1 = DGI.find(" ", nPos0);
// if(nPos1 == string::npos) return -1;
string strId = DGI.substr(nPos0, nPos1 - nPos0 + 1);
cout << strId << endl; */

CString m_ATR="3DDEW553636DD";
char atr[200]={0};
memcpy(atr,m_ATR.GetBuffer(m_ATR.GetLength()),m_ATR.GetLength());
cout<<atr<<endl;
return 0;
}

原文地址:https://www.cnblogs.com/Pond-ZZC/p/10823522.html