Convert String to char[]

  • Thread starter Thread starter Kueishiong Tu
  • Start date Start date
K

Kueishiong Tu

How do I convert a managed String type to a native char[]
type? If nothing is availbale, how do I copy the the
contents of the String object to a char array?
 
Kueishiong Tu said:
How do I convert a managed String type to a native char[]
type? If nothing is availbale, how do I copy the the
contents of the String object to a char array?

What exactly do you mean by "a native char[] type"?

To get the string as a .NET char array, use String.ToCharArray. To get
the string encoded into a byte array, use Encoding.GetBytes.
 
Kueishiong Tu said:
What exactly do you mean by "a native char[] type"?

the original char array type in c or c++ (not managed);

Right - in other words, a byte array.
To get the string as a .NET char array, use
String.ToCharArray.

The compiler required the char array copied to to be
of the type '__wchar_t __gc[]' which is managed.

Ah, if it's __wchar_t[], you might be okay with the .NET char[] type.
Unless I'm much mistaken (which I may well be), __wchar_t is a Unicode
char.
 
Back
Top