Hi. I am currently learning to use Visual C++ from the the Ivor Horton book.

I was just practicing something and i came across a point where i needed to convert an array of wchar_t elements to a System::String^ type.


String^ parse(String^ str)
wchar_t ch = ' '
array<wchar_t>^ returnstr = gcnew array<wchar_t>(10);
int pos = str->IndexOf(ch);
str->CopyTo(0, returnstr, 0, pos);

return returnstr->ToString();

int main(array<System::String^> ^args)
String^ str = L"Hello! one two three";
String^ p = parse(str);

return 0;

I'm Getting This output>>>

Press any key to continue...

My required Output>>>

Press any key to continue...


What my objective for this program is to just display "Hello!" from the "Hello! one two three" string.
And what i REALLY WANT TO TRY is returning a String^ type from the array of wchar_t elements (returnstr).

You may modify the code and show it as your answer..