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. char * to String^

char * to String^

Scheduled Pinned Locked Moved Managed C++/CLI
csharpc++visual-studiotutorial
5 Posts 3 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.
  • K Offline
    K Offline
    KienNT78
    wrote on last edited by
    #1

    Hi all, I got a small trouble, If some one know how to do please tell me, many thanks. I want to assign szData value into textBox->Text, but two kind of variable different type. I used Visual Studio 2005, and developed VC++ language. private: System::Windows::Forms::TextBox^ textBox; private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { char* szData = "abcabcabcabc"; textBox->Text = //Content of szData variable. }

    M N 2 Replies Last reply
    0
    • K KienNT78

      Hi all, I got a small trouble, If some one know how to do please tell me, many thanks. I want to assign szData value into textBox->Text, but two kind of variable different type. I used Visual Studio 2005, and developed VC++ language. private: System::Windows::Forms::TextBox^ textBox; private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { char* szData = "abcabcabcabc"; textBox->Text = //Content of szData variable. }

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      Do you need to use "char*" in managed code?  How about this:

      private: System::Windows::Forms::TextBox^ textBox;
      private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e)
      {
         String ^str = "abcabcabcabc";
         textBox->Text = str;
      }

      or without the extra assignment...

      private: System::Windows::Forms::TextBox^ textBox;
      private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e)
      {
         textBox->Text = "abcabcabcabc";
      }

      Mark


      Last modified: 20mins after originally posted --

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      1 Reply Last reply
      0
      • K KienNT78

        Hi all, I got a small trouble, If some one know how to do please tell me, many thanks. I want to assign szData value into textBox->Text, but two kind of variable different type. I used Visual Studio 2005, and developed VC++ language. private: System::Windows::Forms::TextBox^ textBox; private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { char* szData = "abcabcabcabc"; textBox->Text = //Content of szData variable. }

        N Offline
        N Offline
        Newbie00
        wrote on last edited by
        #3

        How about something like this? textBox->Text = gcnew String(szData);

        K 1 Reply Last reply
        0
        • N Newbie00

          How about something like this? textBox->Text = gcnew String(szData);

          K Offline
          K Offline
          KienNT78
          wrote on last edited by
          #4

          textBox->Text = gcnew String(szData); Yeah, This way I realy like. Can you introduce more about this. How can you find out this way? Do you have any tips for this kind? Sorry, my English very bad.

          N 1 Reply Last reply
          0
          • K KienNT78

            textBox->Text = gcnew String(szData); Yeah, This way I realy like. Can you introduce more about this. How can you find out this way? Do you have any tips for this kind? Sorry, my English very bad.

            N Offline
            N Offline
            Newbie00
            wrote on last edited by
            #5

            Well it's quite simple: You can create String objects with passing char* to the String constructor. 'Text' is something like pointer. gcnew is something like new in c++ but a little bit smarter. So all we have to do is just create new String^ object with szData as value instead of "" ( String is initialized with "" string normally ).

            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