C++/CLI String

Hi,

I am new to .NET CLI. I want to convert a string carat (String^) to character array (char []). Is there a quick way to do that?

Thank you.
Almost none of the regulars know C++/CLI. I recommend that you post in the MSDN Forums.
See if this is what you're trying to do.
1
2
3
4
5
6
String^ stg = "hello";
Char stgChar[5];
for(int i=0;i<stg->Length;i++)
    {
	stgChar[i] = stg[i];
    }
Last edited on
I finally found a post to do that. Thanks anyway!

1
2
3
4
String^ cliString = "hello";
System::IntPtr ptr = System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(cliString);
std::string stdString = static_cast<char *>(ptr.ToPointer());
System::Runtime::InteropServices::Marshal::FreeHGlobal(ptr);
Topic archived. No new replies allowed.