Parsing CString
-
I'v got a CString string as follows CString strPacket = "$1234567FFFFFFFF#00 I want to parse the string so that str1 = "1234567" & str2 = "FFFFFFFF" Any suggestions on how to do this At the moment I'm using the following, however there must be an easier way of doing this. m_strRspData = ""; for(i = 1; i < 9; i++){ m_strHex = m_strRspPacket.GetAt(i); m_strRspData += m_strHex; } m_strRspData.MakeUpper();
-
I'v got a CString string as follows CString strPacket = "$1234567FFFFFFFF#00 I want to parse the string so that str1 = "1234567" & str2 = "FFFFFFFF" Any suggestions on how to do this At the moment I'm using the following, however there must be an easier way of doing this. m_strRspData = ""; for(i = 1; i < 9; i++){ m_strHex = m_strRspPacket.GetAt(i); m_strRspData += m_strHex; } m_strRspData.MakeUpper();
Try Tokenizer class at Codeproject. Robert-Antonio It's a good luck, if you meet a real fink. Then you get a respect to normal, mid-honest people."
-
I'v got a CString string as follows CString strPacket = "$1234567FFFFFFFF#00 I want to parse the string so that str1 = "1234567" & str2 = "FFFFFFFF" Any suggestions on how to do this At the moment I'm using the following, however there must be an easier way of doing this. m_strRspData = ""; for(i = 1; i < 9; i++){ m_strHex = m_strRspPacket.GetAt(i); m_strRspData += m_strHex; } m_strRspData.MakeUpper();
Something like:
int x = 0;
while (isdigit(strPacket[x]))
{
str1 += strPacket[x];
x++;
}str2 = strPacket.Mid(x);
However, if you are always breaking between the 8th and 9th characters, just use
Left()
andMid()
.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)