字符串定义如下 aaa,bbbb,dddd;eeee,ffff,ggggg;hhh.........
需要格式化为二维数组,;分割第一级 , 分割第二级,
我现在使用的是逐个 查找 字符位置,然后处理,虽然可以,但是很痛苦,而且慢,
有没有其它的好办法?比如在javascript 中就有 split 函数直接转换‘
最好给出源代码参考。
谢谢

解决方案 »

  1.   

    使用指针重复查找
    char c[] = "a,b,c,d,e,f";
    char *q = c;
    char *p;
    int j;
    do
    {
    p = q;
    j = strpos( p, ',' );
    if( j == -1 )
    j = strpos( p, finish );
    if( j == -1 )
    return;
    q = p + ( unsigned int )j + 1;
    *( p + ( unsigned char )j ) = 0;
    }
      

  2.   

    自己写函数吧,char *strstr( const char *string, const char *strCharSet );
    不是很麻烦啊
      

  3.   

    哪有没有方便的函数能够得到一个字符串里字符的个数阿?
    比如 "fdsfsf,fdsa,fds,fds," 中查找,出现的个数??
      

  4.   

    See the sample below, useful:http://www.codeproject.com/string/CStringEx.asp
      

  5.   

    If u cannot find the functions u want, u'd design it by yourself
      

  6.   

    This is another sample to search string, FYI :http://www.codeproject.com/string/tier.asp
      

  7.   

    char a[]=",asd,asdf,asdfdf,asdfasdf,a,d";
    CString tempstr;
    tempstr.Format("%s",a);
    int st=tempstr.FindOneOf(",");
    int Number=0;
    while(st!=-1)
    {
    Number++;
    tempstr=tempstr.Mid(st+1);
    AfxMessageBox(tempstr);
    st=tempstr.FindOneOf(",");
    }
    Number就是‘,’的个数