none
vc++.net Split怎么用啊? RRS feed

  • 问题

  • String^ str ="11,22,33,44,55";
    String^ str1[] = str->Split(',');

    这样报错
    1>------ 已启动生成: 项目: JXCGL, 配置: Debug Win32 ------
    1>正在编译...
    1>Windows_tjsp.cpp
    1>c:\documents and settings\mobin\my documents\visual studio 2008\projects\jxcgl\jxcgl\Windows_tjsp.h(320) : error C2728: “System::String ^”: 本机数组不能包含此托管类型
    1>        是否要使用“array<System::String ^>”?
    1>c:\documents and settings\mobin\my documents\visual studio 2008\projects\jxcgl\jxcgl\Windows_tjsp.h(320) : error C2440: “初始化”: 无法从“cli::array<Type,dimension> ^”转换为“System::String ^[]”
    1>        with
    1>        [
    1>            Type=System::String ^,
    1>            dimension=1
    1>        ]
    1>Windows_2.cpp
    1>c:\documents and settings\mobin\my documents\visual studio 2008\projects\jxcgl\jxcgl\Windows_tjsp.h(320) : error C2728: “System::String ^”: 本机数组不能包含此托管类型
    1>        是否要使用“array<System::String ^>”?
    1>c:\documents and settings\mobin\my documents\visual studio 2008\projects\jxcgl\jxcgl\Windows_tjsp.h(320) : error C2440: “初始化”: 无法从“cli::array<Type,dimension> ^”转换为“System::String ^[]”
    1>        with
    1>        [
    1>            Type=System::String ^,
    1>            dimension=1
    1>        ]
    1>Windows_1.cpp
    1>c:\documents and settings\mobin\my documents\visual studio 2008\projects\jxcgl\jxcgl\Windows_tjsp.h(320) : error C2728: “System::String ^”: 本机数组不能包含此托管类型
    1>        是否要使用“array<System::String ^>”?
    1>c:\documents and settings\mobin\my documents\visual studio 2008\projects\jxcgl\jxcgl\Windows_tjsp.h(320) : error C2440: “初始化”: 无法从“cli::array<Type,dimension> ^”转换为“System::String ^[]”
    1>        with
    1>        [
    1>            Type=System::String ^,
    1>            dimension=1
    1>        ]
    1>JXCGL.cpp
    1>c:\documents and settings\mobin\my documents\visual studio 2008\projects\jxcgl\jxcgl\Windows_tjsp.h(320) : error C2728: “System::String ^”: 本机数组不能包含此托管类型
    1>        是否要使用“array<System::String ^>”?
    1>c:\documents and settings\mobin\my documents\visual studio 2008\projects\jxcgl\jxcgl\Windows_tjsp.h(320) : error C2440: “初始化”: 无法从“cli::array<Type,dimension> ^”转换为“System::String ^[]”
    1>        with
    1>        [
    1>            Type=System::String ^,
    1>            dimension=1
    1>        ]
    1>正在生成代码...
    1>生成日志保存在“file://c:\Documents and Settings\MoBin\My Documents\Visual Studio 2008\Projects\JXCGL\JXCGL\Debug\BuildLog.htm”
    1>JXCGL - 8 个错误,0 个警告
    ========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========

    2010年11月4日 3:52

答案

  • FYI.

    String^ str ="11,22,33,44,55";
    array<Char>^ chars = {','};
    array<String^>^ str1 = str->Split(chars);
    IEnumerator^ strEnum = str1->GetEnumerator();
       while ( strEnum->MoveNext() )
       {
          String^ s = safe_cast<String^>(strEnum->Current);
                      .........
       }


    Would you know my name, if I saw you in heaven......
    • 已标记为答案 Ballsky 2010年11月7日 9:42
    2010年11月5日 7:11
    版主