Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. String.Split not functioning correctly?

String.Split not functioning correctly?

Scheduled Pinned Locked Moved Managed C++/CLI
csharpdata-structureshelpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jmlsteele
    wrote on last edited by
    #1

    ---CODE--- // Split Test: String::Split does NOT work properly when given a # of substrings to return void splitTest() { String^ toBeSplit = "a b c d e f g h"; array^ split = toBeSplit->Split(' ',3); //Expected: "Count: 3" Actual "Count: 8" Console::WriteLine("Count: {0}",split->Length); } ---END CODE--- Am I doing something ridiculously stupid, or is this really a bug? The equivilent C# code works properly.

    L 1 Reply Last reply
    0
    • J jmlsteele

      ---CODE--- // Split Test: String::Split does NOT work properly when given a # of substrings to return void splitTest() { String^ toBeSplit = "a b c d e f g h"; array^ split = toBeSplit->Split(' ',3); //Expected: "Count: 3" Actual "Count: 8" Console::WriteLine("Count: {0}",split->Length); } ---END CODE--- Am I doing something ridiculously stupid, or is this really a bug? The equivilent C# code works properly.

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      jmlsteele wrote:

      toBeSplit->Split(' ',3);

      I don't know how you got that to compile but the following works as expected

      array<wchar_t>^ delim = gcnew array<wchar_t> {' '};
      String^ src = "1 2 3 4 5";
      array<String^>^ a1 = src->Split( delim);
      Console::WriteLine( String::Format("{0}", a1->Length));
      a1 = src->Split( delim, 2);
      Console::WriteLine( String::Format("{0}", a1->Length));

      led mike

      J 1 Reply Last reply
      0
      • L led mike

        jmlsteele wrote:

        toBeSplit->Split(' ',3);

        I don't know how you got that to compile but the following works as expected

        array<wchar_t>^ delim = gcnew array<wchar_t> {' '};
        String^ src = "1 2 3 4 5";
        array<String^>^ a1 = src->Split( delim);
        Console::WriteLine( String::Format("{0}", a1->Length));
        a1 = src->Split( delim, 2);
        Console::WriteLine( String::Format("{0}", a1->Length));

        led mike

        J Offline
        J Offline
        jmlsteele
        wrote on last edited by
        #3

        I get no errors, and no warnings when compiling what I posted, and upon further inspection I realise why. The first entry you get for intellisense is Split(... cli::array<__wchar_t,1> ^seperator) so it's just converting my 3 into a wchar_t. Now I feel stupid... Thanks for your help.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups