如何处理这个字符串str=“11,陆亚讯,19200,FFFF,1,0,0,0,0,0,4,3”

如何处理这个字符串str=“11,陆亚讯,19200,FFFF,1,0,0,0,0,0,4,3”


主      题: 如何处理这个字符串str=“11,陆亚讯,19200,FFFF,1,0,0,0,0,0,4,3” 
作      者: isabc ( 书童)
所属论坛: Visual C++论坛
本帖分数: 5
回复次数: 12
发表时间: 2007-9-6 15:15:28
正文内容:
根据逗号,取出每个逗号间的信息!
从str中得到
str0 = “11”;
str1 = “陆亚讯”;
str2 = “19200”;
str3 = “FFFF”;
str4 = “1”;
str5 = “0”;
str6 = “0”;
最新修改:2007-9-6 15:56:49
回复人: shuishi32 ( 进士)  2007-9-6 15:30:00
下面没试
    CString str="11,陆亚讯,19200,FFFF,1,0,0,0,0,0,4,3";
    int nPos1 = 0;
    int nPos2 = 0;
    CString st[20];
    int i = 0;
    for( (nPos2 = str.Find(',')) != -1)
    {
        st[i++] = str.Mid(nPos1, nPos2 - nPos1);
        nPos1 = nPos2+1;
    }

回复人: 山丘之王 ( 秀才)  2007-9-6 15:37:04
...
CStringArray arr;
arr.setsize...
int old=-1,new=0;
while(true)
{
old = new ;
new = str.Find(',');
if(new <1)
{
arr.Add(str.Mid(old+1,str.GetLenth()));
break;
}
arr.Add(str.Mid(old+1,new));
}

回复人: isabc ( 书童)  2007-9-7 17:03:11  [修改]
Re:如何处理这个字符串str=“11,陆亚讯,19200,FFFF,1,0,0,0,0,0,4,3”
问题我已经解决了,使用 山丘之王和 shuishi32的代码都不通过,不过你们的代码还是有参考价值的,谢谢阿,送分了!!
for(int i=0; i<Str.GetLength (); i++ )
            {
                if((pos1=Str.Find (',',pos0))!=-1)
                {
                    //Str1 = Str.Left (1);
                    Count = pos1 - pos0 ;
                    Str1 = Str.Mid (pos0,Count);
                    pos0 = pos1 + 1;
                    StrArray.Add (Str1);    
                }
            }
            int X = StrArray.GetSize ();
            m_strCardNo = StrArray.GetAt (0);
            m_strCardName = StrArray.GetAt (1);

你可能感兴趣的:(如何处理这个字符串str=“11,陆亚讯,19200,FFFF,1,0,0,0,0,0,4,3”)