Menu Close

Convert System::String to char* and vice versa

 Convert System::String to char*

char* ConvertStringToChar( String^ str)

{

           using namespace Runtime::InteropServices;

          IntPtr p = Marshal::StringToHGlobalAnsi(str);

          return static_cast<char*>(p.ToPointer());

 }

 Convert char* to System::String

 String^ ConvertCharToString(char* strChar, int length)

{

       String^ msg = gcnew String((char*)strChar);

      if (msg->Length > length)

      msg = msg->Substring(0, length);

     return msg;

}

Leave a Reply

Your email address will not be published. Required fields are marked *

*

* Copy This Password *

* Type Or Paste Password Here *

18,577 Spam Comments Blocked so far by Spam Free Wordpress

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>