How can I convert System :: String to unsigned char *?

I saw another post that suggested the following:

String^ clistr = gcnew String("sample");
IntPtr p = Marshal::StringToHGlobalAnsi(clistr);
char *pNewCharStr = static_cast<char*>(p.ToPointer());
Marshal::FreeHGlobal(p);

      

I just wanted to check and see if there is some other, preferred way or something wrong with this?

-1


a source to share


1 answer


The first result on google for "System :: String char *" seems to offer a fairly complete guide. http://support.microsoft.com/kb/311259



+3


a source







All Articles