none
Converting unmanaged string into managed one RRS feed

  • Question

  • Hi,

    How can I convert unmanaged string into a managed one? I want to do something like this:

    char s[] = "Application Title";

    // some code

    this.Text = s;

    I got that char[] could be converted into String^.

    Saturday, May 18, 2013 4:34 PM

Answers

  • Hi,
     
    How can I convert unmanaged string into a managed one? I want to do something like this:
     
    char s[] = "Application Title";
     
    // some code
     
    this.Text = s;
     
    I got that char[] could be converted into String^.
    System::String has conversion constructors from const char* and const wchar_t*. In the first case, the string is converted to UTF-16 using the local code page.
     
    this->Text = gcnew String(s);
     

    David Wilkinson | Visual C++ MVP
    • Marked as answer by BGQQ Saturday, May 18, 2013 5:09 PM
    Saturday, May 18, 2013 4:57 PM

All replies

  • Hi,
     
    How can I convert unmanaged string into a managed one? I want to do something like this:
     
    char s[] = "Application Title";
     
    // some code
     
    this.Text = s;
     
    I got that char[] could be converted into String^.
    System::String has conversion constructors from const char* and const wchar_t*. In the first case, the string is converted to UTF-16 using the local code page.
     
    this->Text = gcnew String(s);
     

    David Wilkinson | Visual C++ MVP
    • Marked as answer by BGQQ Saturday, May 18, 2013 5:09 PM
    Saturday, May 18, 2013 4:57 PM
  • It works. Thank you very much.
    Saturday, May 18, 2013 5:09 PM