String.Split not functioning correctly?
-
---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.
-
---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.
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
-
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
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.