假设有个字符数组bufPohne
char bufPohne[2100] = "111;222;333;444"; //字符串数组,里面存储的数字字符以分号隔开另外有数组bufRecv
char bufRecv[4096];我想bufRecv中的字符如下格式: "The number is:111 The number is:222 The number is:333 The number is:444"
其中111,222,333,444为bufPohne中分离出来的字符串这应该如何处理,希望高手指点 谢谢
char bufPohne[2100] = "111;222;333;444"; //字符串数组,里面存储的数字字符以分号隔开另外有数组bufRecv
char bufRecv[4096];我想bufRecv中的字符如下格式: "The number is:111 The number is:222 The number is:333 The number is:444"
其中111,222,333,444为bufPohne中分离出来的字符串这应该如何处理,希望高手指点 谢谢
{
char tmpchar = str1.GetAt(i);
if((tmpchar==';')||(i==0))
{
CString str2;
if(i==0)
str2="The number is:"+str1.Mid(i,3);
else
str2="The number is:"+str1.Mid(i+1,3);
MessageBox(str2);
}
}
不过char bufPohne[2100] = "111;222;333;444"; 中的数字字符不一定是定长的。
比如有可能是char bufPohne[2100] = "111;2222;33;4444444";
CSting strBufPohne = bufPohne;
CString strTmp = _T(";") + strBufPohne;
strTmp.Replace(_T(";"), _T(" The number is:"));
然后再把strTmp中的内容填回到bufRecv中
char bufRecv[4096];
CString cstr1 = (char*)bufPohne;
CString cstr2;
int a;
for(;;)
{
a= cstr1.Find(';');
if( a == -1 )break;
cstr2 += _T(" The number is:") + cstr1.Left(a);
cstr1 = cstr1.Right(cstr1.GetLength() - a - 1);
}
strcpy((char*)bufRecv,cstr2);