如CString str1("1112AAA测试汉字ssss,,ffffffffffffffffffwwwwwwwwd地工");
.........
........
获得的结果CString str2 等于
1112AAA测试汉字ssss,,fff

解决方案 »

  1.   

    int nCharNum = 0;
    for(int i=0;i<str1.GetLength();i++)
    {
        char ch = str1.GetAt(i);
        if(ch & 0x80)
            i++;
        nCharNum ++;
       if(nCharNum >= 20)
            break;
    }
    str2 = str1.Left(i);
      

  2.   

    CString str1("1112AAA测试汉字ssss,,ffffffffffffffffffwwwwwwwwd地工");
    // 如果不是UNICODE环境下
    CStringW str2(str1);
    str2.Left(20);// 如果 UNICODE环境下
    str1.Left(20);
      

  3.   

    CString str1("1112AAA测试汉字ssss,,ffffffffffffffffffwwwwwwwwd地工");int i;
    LPCTSTR psz = str1;
    for (i=0;i<20;++i)
    {
       if (*psz == 0)
         break;
       psz = ::CharNext (psz);
    };
    str1 = str1.Left (psz-(LPCTSTR)str1);
      

  4.   

    支持: xstring(麻雀) happyparrot(快乐鹦鹉) 对“,”的处理好像不太对。
      

  5.   

    非UNICODE下的不说了,直接用GetLength()就可以
    UNICODE下:
           CString csDemo="111我的测试!222aaabbb";
          WCHAR wcSend[1024];
          TCHAR tcSend[1024];
           int iLength=csDemo.GetLength();
          strcpy(tcSend,csDemo.GetBuffer(csDemo.GetLength()));csDemo.ReleaseBuffer();
         MultiByteToWideChar(CP_ACP,0,tcSend,-1, wcSend,1024)
         wcsset(wcSend+iLength,'\0');
         int iTCLength=WideCharToMultiByte(CP_ACP,0,wcSend,-1, tcSend,1024,NULL,false);
         tcSend[iTCLength]='\0';
         int iMyLengthResult=strlen(tcSend);
         iMyLengthResult就是你要的结果了
      

  6.   

    看错了,以为你要取得长度,xstring说的我以前就这么用的,可以的
      

  7.   

    happyparrot(快乐鹦鹉)和xstring(麻雀) 的处理结果对于汉字来说都是没什么问题的