比如说:
少林功夫好,真 是 好,小 林 功 夫棒,真是 棒,他是 金 刚腿,我是铁头功。
敏感数据时 金刚腿
则返回
....他是金刚腿,我是铁头功。我知道用CString的Find和Mid,
可是当用Mid取值的时候,Mid(s,start,length)
以为有的字占2位字符,而有的只占1位,
如果取错了就出现乱码,
请问该怎么办
只能将所有的都转为unicode字符,可是转完后又不能用CString的一些函数了,比如
find,mid等

解决方案 »

  1.   

    你最好用STL的string比较好一点~
      

  2.   

    我想实现这样的"沧海r医生小"这一个字符串
    如果用Mid(2,4)
    想要的结果是"海r",
    而不是"海r?"
    这个怎么整 
    如何将r变成2个字符的宽度
      

  3.   

    你可以使用STL中的
    typedef basic_string<wchar_t> STRING;然后你就可以使用STRING类的find和substr()来提取你想要的子串
      

  4.   

    楼上的4星哥哥能否说的详细点,我是个菜鸟
    帮帮忙吧,想了好几天了
    还有
    typedef basic_string<wchar_t> STRING;
    是什么意思,
    我该怎么顶一字符串,这个字符串很长
      

  5.   

    STL中的basic_string<>是一个模板类
    而string使用basic_string<>定义的一个类型别名,其中模板参数是ANSI字符char
    也就是
    typedef basic_string<char> string;wchar_t是UNICODE字符
    你可以按上面的方法定义一个容纳UNICODE字符的字符串
    typedef basic_string<wchar_t> STRING;
    这样定义的STRING类就可以容纳UNICODE字符
    由于STRING只是basic_string<>模板类的一个特化版本
    在STRING中你一样可以使用basic_string<>中的成员函数find以及substr()来提取整个字符串中你感兴趣的子串!find函数原型
    size_type find(
       value_type _Ch, 
       size_type _Off = 0
    ) const;
    size_type find(
       const value_type* _Ptr,
       size_type _Off = 0
    ) const;
    size_type find(
       const value_type* _Ptr, 
       size_type _Off = 0,
       size_type _Count
    ) const;
    size_type find(
       const basic_string& _Str,
       size_type _Off = 0
    ) const;substr函数原型
    basic_string substr(
       size_type _Off = 0,
       size_type _Count = npos
    ) const;
    这两个函数的功能相当与CString类中的Find函数和Mid函数
    使用方法基本相同!更多关于basic_string<>模板类的信息,参考一下MSDN !参考一下
    #include <string>
    #include <iostream>
    typedef basic_string<wchar_t> STRING;
    void main( ) 
    {
       using namespace std;   STRING  str1 ("Heterological paradoxes are persistent.");
       cout << "The original string str1 is: \n " << str1
            << endl << endl;   STRING str2 = str1.substr ( 6 , 7 );
       cout << "The substring str1 copied is: " << str2
            << endl << endl;
       
       STRING str3 = str1.substr (  );
       cout << "The default substring str3 is: \n " << str3
            <<  "\n which is the entire original string." << endl;
    }希望对你有所帮助!
      

  6.   

    #include <string>
    #include <iostream>
    using namespace std;
    typedef basic_string<wchar_t> STRING;int main(int argc, char* argv[])
    {
    STRING str1(L"&sup2;×&ordm;&pound;2&Ograve;&frac12;&Eacute;ú&ETH;&iexcl;");
    STRING str2 = str1.substr(2,4);
    return 0;
    }
      

  7.   

    谁说用了unicode后CString类的函数用不了
    我就是使用unicode处理的带有中英文的字符串
      

  8.   

    老大,怎么用UNICODE处理带有中英文的字符串
      

  9.   

    在project->settings->c/c++->preprocessor definitions编辑框中加入“,UNICODE,_UNICODE”,注意要加入一些处理unicode的lib如mfc42ud.lib等等,可以在vc的安装盘中找到。
    然后在Link’ tab, category ‘output’设置‘Entry-point symbol’为 ‘wWinMainCRTStartup’.这样以后,你就可以处理unicode字符串,使用CString类定义的字符串应该加上_T,例如
    CString msg = _T("I am 龙行天下");
    assert(msg.GetLength() == 9);
    assert(sizeof(msg) == 13);
    assert(msg.Find(_T("行")) == 6);